/** * 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. */ #import #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(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)dummyHandler:(FBRouteRequest *)request { return nil; } @end