@@ -622,4 +622,64 @@ - (void)testAuthorizeWithoutLocalAccountAndNetworkSuccess {
622622 OCMVerifyAll (mockedURLSession);
623623}
624624
625+ - (void )testDeauthorizeLoggedOutAccount {
626+ id store = PFStrictClassMock ([ACAccountStore class ]);
627+ NSURLSession *session = PFStrictClassMock ([NSURLSession class ]);
628+ id mockedDialog = PFStrictProtocolMock (@protocol (PFOAuth1FlowDialogInterface));
629+ PF_Twitter *twitter = [[PF_Twitter alloc ] initWithAccountStore: store urlSession: session dialogClass: mockedDialog];
630+
631+ XCTestExpectation *expectation = [self currentSelectorTestExpectation ];
632+ [[twitter authorizeInBackground ] continueWithBlock: ^id (BFTask *task) {
633+ NSError *error = task.error ;
634+ XCTAssertNotNil (error);
635+ XCTAssertEqualObjects (error.domain , PFParseErrorDomain);
636+ XCTAssertEqual (error.code , 1 );
637+ [expectation fulfill ];
638+ return nil ;
639+ }];
640+ [self waitForTestExpectations ];
641+ }
642+
643+ - (void )testDeauthorizeLoggedInAccount {
644+ id mockedStore = PFStrictClassMock ([ACAccountStore class ]);
645+ id mockedURLSession = PFStrictClassMock ([NSURLSession class ]);
646+ id mockedOperationQueue = PFStrictClassMock ([NSOperationQueue class ]);
647+
648+ id mockedDialog = PFStrictProtocolMock (@protocol (PFOAuth1FlowDialogInterface));
649+ PF_Twitter *twitter = [[PF_Twitter alloc ] initWithAccountStore: mockedStore urlSession: mockedURLSession dialogClass: mockedDialog];
650+ twitter.consumerKey = @" consumer_key" ;
651+ twitter.consumerSecret = @" consumer_secret" ;
652+ twitter.authToken = @" auth_token" ;
653+ twitter.authTokenSecret = @" auth_token_secret" ;
654+ twitter.userId = @" user_id" ;
655+ twitter.screenName = @" screen_name" ;
656+
657+ __block NSURLSessionDataTaskCompletionHandler completionHandler = nil ;
658+ [OCMStub ([mockedURLSession dataTaskWithRequest: [OCMArg checkWithBlock: ^BOOL (id obj) {
659+ NSURLRequest *request = obj;
660+ return [request.URL.lastPathComponent isEqualToString: @" invalidate_token" ];
661+ }] completionHandler: [OCMArg checkWithBlock: ^BOOL (id obj) {
662+ completionHandler = obj;
663+ return (obj != nil );
664+ }]]).andDo (^(NSInvocation *invocation) {
665+ completionHandler ([NSData data ], nil , nil );
666+ }) andReturn: [OCMockObject niceMockForClass: [NSURLSessionDataTask class ]]];
667+
668+ XCTestExpectation *expectation = [self currentSelectorTestExpectation ];
669+ [[twitter deauthorizeInBackground ] continueWithBlock: ^id (BFTask *task) {
670+ NSError *error = task.error ;
671+ XCTAssertNil (error);
672+ XCTAssertNotNil (task.result );
673+
674+ XCTAssertNil (twitter.authToken );
675+ XCTAssertNil (twitter.authTokenSecret );
676+ XCTAssertNil (twitter.userId );
677+ XCTAssertNil (twitter.screenName );
678+
679+ [expectation fulfill ];
680+ return nil ;
681+ }];
682+ [self waitForTestExpectations ];
683+ }
684+
625685@end
0 commit comments