Skip to content

Commit

Permalink
refactor to reuse setConfiguration instead of writting everything again
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres Canal committed Jun 16, 2016
1 parent 375cbfa commit ca59ae0
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 77 deletions.
3 changes: 0 additions & 3 deletions Extensions/XMPPMUCLight/XMPPRoomLight.h
Expand Up @@ -65,9 +65,6 @@
- (void)xmppRoomLight:(nonnull XMPPRoomLight *)sender didFetchMembersList:(nonnull NSArray<NSXMLElement*> *)items;
- (void)xmppRoomLight:(nonnull XMPPRoomLight *)sender didFailToFetchMembersList:(nonnull XMPPIQ *)iq;

- (void)xmppRoomLight:(nonnull XMPPRoomLight *)sender didChangeRoomSubject:(nonnull XMPPIQ*) iqResult;
- (void)xmppRoomLight:(nonnull XMPPRoomLight *)sender didFailToChangeroomSubject:(nonnull XMPPIQ*)iq;

- (void)xmppRoomLight:(nonnull XMPPRoomLight *)sender didDestroyRoomLight:(nonnull XMPPIQ*) iqResult;
- (void)xmppRoomLight:(nonnull XMPPRoomLight *)sender didFailToDestroyRoomLight:(nonnull XMPPIQ*)iq;

Expand Down
40 changes: 1 addition & 39 deletions Extensions/XMPPMUCLight/XMPPRoomLight.m
Expand Up @@ -339,47 +339,9 @@ - (void)sendMessageWithBody:(nonnull NSString *)messageBody{
}

- (void)changeRoomSubject:(nonnull NSString *)roomSubject{
dispatch_block_t block = ^{ @autoreleasepool {

// <iq from='hag66@shakespeare.lit/pda'
// id='subject1'
// to='coven@muclight.shakespeare.lit'
// type='set'>
// <query xmlns='urn:xmpp:muclight:0#configuration'>
// <subject>To be or not to be?</subject>
// </query>
// </iq>

NSString *iqID = [XMPPStream generateUUID];
XMPPIQ *iq = [XMPPIQ iqWithType:@"set" to:_roomJID elementID:iqID];
NSXMLElement *query = [NSXMLElement elementWithName:@"query" xmlns:XMPPRoomLightConfiguration];
[iq addChild:query];

XMPPElement *subject = [NSXMLElement elementWithName:@"subject"];
subject.stringValue = roomSubject;

[query addChild:subject];

[responseTracker addID:iqID
target:self
selector:@selector(handleChangeRoomSubjectResponse:withInfo:)
timeout:60.0];

[xmppStream sendElement:iq];
}};

if (dispatch_get_specific(moduleQueueTag))
block();
else
dispatch_async(moduleQueue, block);
}
[self setConfiguration:@[[NSXMLElement elementWithName:@"subject" stringValue:roomSubject]]];

- (void)handleChangeRoomSubjectResponse:(XMPPIQ *)iq withInfo:(id <XMPPTrackingInfo>)info{
if ([[iq type] isEqualToString:@"result"]) {
[multicastDelegate xmppRoomLight:self didChangeRoomSubject:iq];
}else{
[multicastDelegate xmppRoomLight:self didFailToChangeroomSubject:iq];
}
}

- (void)changeAffiliations:(nonnull NSArray<NSXMLElement *> *)members{
Expand Down
35 changes: 0 additions & 35 deletions Xcode/Testing-pod/XMPPFrameworkTests/XMPPRoomLightTests.m
Expand Up @@ -425,41 +425,6 @@ - (void)xmppRoomLight:(XMPPRoomLight *)sender configurationChanged:(XMPPMessage
self.receivedConfigurationChangedMessage = YES;
}

- (void)xmppRoomLight:(XMPPRoomLight *)sender didChangeRoomSubject:(XMPPIQ *)iqResult {
XCTAssertTrue(self.receivedConfigurationChangedMessage);
[self.delegateResponseExpectation fulfill];
}

- (void)testFailToChangeSubject{
self.delegateResponseExpectation = [self expectationWithDescription:@"change subject"];

XMPPMockStream *streamTest = [[XMPPMockStream alloc] init];
XMPPJID *roomJID = [XMPPJID jidWithString:@"room-id@domain.com"];

XMPPRoomLight *roomLight = [[XMPPRoomLight alloc] initWithJID:roomJID roomname:@"roomName"];
[roomLight activate:streamTest];
[roomLight addDelegate:self delegateQueue:dispatch_get_main_queue()];

__weak typeof(XMPPMockStream) *weakStreamTest = streamTest;
streamTest.elementReceived = ^void(NSXMLElement *element) {
NSString *iqID = [element attributeForName:@"id"].stringValue;
XMPPIQ *iq = [self fakeIQWithID:iqID andType:@"error"];
[weakStreamTest fakeIQResponse:iq];
};

[roomLight changeRoomSubject:@"new subject"];

[self waitForExpectationsWithTimeout:2 handler:^(NSError * _Nullable error) {
if(error){
XCTFail(@"Expectation Failed with error: %@", error);
}
}];
}

- (void)xmppRoomLight:(XMPPRoomLight *)sender didFailToChangeroomSubject:(nonnull XMPPIQ *)iq {
[self.delegateResponseExpectation fulfill];
}

- (void)testDestroyRoom{
self.receivedDestroyMessage = NO;
self.delegateResponseExpectation = [self expectationWithDescription:@"delete room"];
Expand Down

0 comments on commit ca59ae0

Please sign in to comment.