Skip to content

Commit 5bdd69b

Browse files
authored
TestCore implements TestSpy pattern (#393)
* make TestCore implement the Test Spy pattern and add a test * refactor TestCore query methods * revert 793dce5 but keep the refactored interface
1 parent b135684 commit 5bdd69b

File tree

11 files changed

+58
-4
lines changed

11 files changed

+58
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
testing
2+
testPositionIsUpdatedAfterInitialChatLoading
3+
4+
| testChat newChatEvent updatePositionEvent |
5+
6+
testChat := self sharedCore chats first.
7+
self assert: testChat positionKnown.
8+
9+
newChatEvent := (self sharedCore loggedEventsSatisfying:
10+
[:anEvent | anEvent type = 'updateNewChat' and: [((anEvent at: 'chat') at: 'id') = testChat id]])
11+
first.
12+
updatePositionEvent := (self sharedCore loggedEventsSatisfying:
13+
[:anEvent | anEvent type = 'updateChatPosition' and: [(anEvent at: 'chat_id') = testChat id]])
14+
first.
15+
16+
self assert: (self sharedCore chronologicalPositionOf: newChatEvent) < (self sharedCore chronologicalPositionOf: updatePositionEvent).

packages/TelegramClientTests-Core.package/TCTCAPITests.class/methodProperties.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
},
44
"instance" : {
55
"testExtraAPIAttribute" : "RS 6/6/2021 10:50",
6-
"testMessageSending" : "RS 6/6/2021 10:54" } }
6+
"testMessageSending" : "RS 6/6/2021 10:54",
7+
"testPositionIsUpdatedAfterInitialChatLoading" : "RS 6/13/2021 17:02" } }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Creates a TestApp using Telegram TestDatabase Service
1+
Creates a TestApp using Telegram TestDatabase Service and saves all received events in-order in a log.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
event log querying
2+
chronologicalPositionOf: anEvent
3+
4+
| position |
5+
6+
position := self eventLog findFirst: [:anotherEvent | anotherEvent = anEvent].
7+
self assert: (position = 0) not.
8+
9+
^ position
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
accessing
2+
eventLog: anOrderedCollection
3+
4+
eventLog := anOrderedCollection
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
accessing
2+
eventLog
3+
4+
^ eventLog
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
events
2+
handleEvent: anEvent
3+
4+
self eventLog add: anEvent.
5+
^ super handleEvent: anEvent
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
initialization
2+
initialize
3+
4+
self eventLog: OrderedCollection new.
5+
super initialize.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
event log querying
2+
loggedEventsSatisfying: aBlock
3+
4+
^ self eventLog select: aBlock

packages/TelegramClientTests-Core.package/TCTCTestCore.class/methodProperties.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,11 @@
22
"class" : {
33
},
44
"instance" : {
5+
"chronologicalPositionOf:" : "RS 6/13/2021 17:05",
6+
"eventLog" : "RS 6/13/2021 12:31",
7+
"eventLog:" : "RS 6/13/2021 12:32",
8+
"handleEvent:" : "RS 6/13/2021 12:34",
9+
"initialize" : "RS 6/13/2021 12:47",
510
"initializeHandlers" : "JB 6/7/2021 09:27",
11+
"loggedEventsSatisfying:" : "RS 6/13/2021 17:06",
612
"loginWithTestData" : "RS 5/26/2021 13:57" } }

packages/TelegramClientTests-Core.package/TCTCTestCore.class/properties.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
],
55
"classvars" : [
66
],
7-
"commentStamp" : "rs 6/14/2020 12:57",
7+
"commentStamp" : "RS 6/13/2021 13:04",
88
"instvars" : [
9-
],
9+
"eventLog" ],
1010
"name" : "TCTCTestCore",
1111
"pools" : [
1212
],

0 commit comments

Comments
 (0)