| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- /**
- * Copyright (c) 2015-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- */
- #import <XCTest/XCTest.h>
- #import "FBRoute.h"
- @class RouteResponse;
- @interface FBHandlerMock : NSObject
- @property (nonatomic, assign) BOOL didCallSomeSelector;
- @end
- @implementation FBHandlerMock
- - (id)someSelector:(id)arg
- {
- self.didCallSomeSelector = YES;
- return nil;
- };
- @end
- @interface FBRouteTests : XCTestCase
- @end
- @implementation FBRouteTests
- - (void)testGetRoute
- {
- FBRoute *route = [FBRoute GET:@"/"];
- XCTAssertEqualObjects(route.verb, @"GET");
- }
- - (void)testPostRoute
- {
- FBRoute *route = [FBRoute POST:@"/"];
- XCTAssertEqualObjects(route.verb, @"POST");
- }
- - (void)testPutRoute
- {
- FBRoute *route = [FBRoute PUT:@"/"];
- XCTAssertEqualObjects(route.verb, @"PUT");
- }
- - (void)testDeleteRoute
- {
- FBRoute *route = [FBRoute DELETE:@"/"];
- XCTAssertEqualObjects(route.verb, @"DELETE");
- }
- - (void)testTargetAction
- {
- FBHandlerMock *mock = [FBHandlerMock new];
- FBRoute *route = [[FBRoute new] respondWithTarget:mock action:@selector(someSelector:)];
- [route mountRequest:(id)NSObject.new intoResponse:(id)NSObject.new];
- XCTAssertTrue(mock.didCallSomeSelector);
- }
- - (void)testRespond
- {
- XCTestExpectation *expectation = [self expectationWithDescription:@"Calling respond block works!"];
- FBRoute *route = [[FBRoute new] respondWithBlock:^id<FBResponsePayload>(FBRouteRequest *request) {
- [expectation fulfill];
- return nil;
- }];
- [route mountRequest:(id)NSObject.new intoResponse:(id)NSObject.new];
- [self waitForExpectationsWithTimeout:0.0 handler:nil];
- }
- - (void)testRouteWithSessionWithSlash
- {
- FBRoute *route = [[FBRoute POST:@"/deactivateApp"] respondWithTarget:self action:@selector(dummyHandler:)];
- XCTAssertEqualObjects(route.path, @"/session/:sessionID/deactivateApp");
- }
- - (void)testRouteWithSession
- {
- FBRoute *route = [[FBRoute POST:@"deactivateApp"] respondWithTarget:self action:@selector(dummyHandler:)];
- XCTAssertEqualObjects(route.path, @"/session/:sessionID/deactivateApp");
- }
- - (void)testRouteWithoutSessionWithSlash
- {
- FBRoute *route = [[FBRoute POST:@"/deactivateApp"].withoutSession respondWithTarget:self action:@selector(dummyHandler:)];
- XCTAssertEqualObjects(route.path, @"/deactivateApp");
- }
- - (void)testRouteWithoutSession
- {
- FBRoute *route = [[FBRoute POST:@"deactivateApp"].withoutSession respondWithTarget:self action:@selector(dummyHandler:)];
- XCTAssertEqualObjects(route.path, @"/deactivateApp");
- }
- - (void)testEmptyRouteWithSession
- {
- FBRoute *route = [[FBRoute POST:@""] respondWithTarget:self action:@selector(dummyHandler:)];
- XCTAssertEqualObjects(route.path, @"/session/:sessionID");
- }
- - (void)testEmptyRouteWithoutSession
- {
- FBRoute *route = [[FBRoute POST:@""].withoutSession respondWithTarget:self action:@selector(dummyHandler:)];
- XCTAssertEqualObjects(route.path, @"/");
- }
- - (void)testEmptyRouteWithSessionWithSlash
- {
- FBRoute *route = [[FBRoute POST:@"/"] respondWithTarget:self action:@selector(dummyHandler:)];
- XCTAssertEqualObjects(route.path, @"/session/:sessionID");
- }
- - (void)testEmptyRouteWithoutSessionWithSlash
- {
- FBRoute *route = [[FBRoute POST:@"/"].withoutSession respondWithTarget:self action:@selector(dummyHandler:)];
- XCTAssertEqualObjects(route.path, @"/");
- }
- + (id<FBResponsePayload>)dummyHandler:(FBRouteRequest *)request
- {
- return nil;
- }
- @end
|