@@ -22,96 +22,100 @@ import XCTVapor
2222final class MastodonTests : AppTestCase {
2323
2424 func test_endToEnd( ) async throws {
25- // setup
26- let message = QueueIsolated < String ? > ( nil )
27- Current . mastodonPost = { _, msg in
28- if message. value == nil {
29- message. setValue ( msg)
30- } else {
31- XCTFail ( " message must only be set once " )
25+ try await withDependencies {
26+ $0. environment. allowSocialPosts = { true }
27+ } operation: {
28+ // setup
29+ let message = QueueIsolated < String ? > ( nil )
30+ Current . mastodonPost = { _, msg in
31+ if message. value == nil {
32+ message. setValue ( msg)
33+ } else {
34+ XCTFail ( " message must only be set once " )
35+ }
3236 }
33- }
34-
35- let url = " https://github.com/foo/bar "
36- Current . fetchMetadata = { _, owner, repository in . mock( owner: owner, repository: repository) }
37-
38- Current . git. commitCount = { @Sendable _ in 12 }
39- Current . git. firstCommitDate = { @Sendable _ in . t0 }
40- Current . git. lastCommitDate = { @Sendable _ in . t2 }
41- Current . git. getTags = { @Sendable _ in [ Reference . tag ( 1 , 2 , 3 ) ] }
42- Current . git. hasBranch = { @Sendable _, _ in true }
43- Current . git. revisionInfo = { @Sendable _, _ in . init( commit: " sha " , date: . t0) }
44- Current . git. shortlog = { @Sendable _ in
37+
38+ let url = " https://github.com/foo/bar "
39+ Current . fetchMetadata = { _, owner, repository in . mock( owner: owner, repository: repository) }
40+
41+ Current . git. commitCount = { @Sendable _ in 12 }
42+ Current . git. firstCommitDate = { @Sendable _ in . t0 }
43+ Current . git. lastCommitDate = { @Sendable _ in . t2 }
44+ Current . git. getTags = { @Sendable _ in [ Reference . tag ( 1 , 2 , 3 ) ] }
45+ Current . git. hasBranch = { @Sendable _, _ in true }
46+ Current . git. revisionInfo = { @Sendable _, _ in . init( commit: " sha " , date: . t0) }
47+ Current . git. shortlog = { @Sendable _ in
4548 """
4649 10 \t Person 1
4750 2 \t Person 2
4851 """
49- }
50-
51- Current . shell. run = { @Sendable cmd, path in
52- if cmd. description. hasSuffix ( " swift package dump-package " ) {
53- return #"{ "name": "Mock", "products": [], "targets": [] }"#
5452 }
55- return " "
56- }
57-
58- try await withDependencies {
59- $0. date. now = . now
60- $0. packageListRepository. fetchPackageList = { @Sendable _ in [ url. url] }
61- $0. packageListRepository. fetchPackageDenyList = { @Sendable _ in [ ] }
62- $0. packageListRepository. fetchCustomCollections = { @Sendable _ in [ ] }
63- $0. packageListRepository. fetchCustomCollection = { @Sendable _, _ in [ ] }
64- } operation: {
65- // run first two processing steps
66- try await reconcile ( client: app. client, database: app. db)
67- try await ingest ( client: app. client, database: app. db, mode: . limit( 10 ) )
68-
69- // MUT - analyze, triggering the post
70- try await Analyze . analyze ( client: app. client,
71- database: app. db,
72- mode: . limit( 10 ) )
73-
74- do {
75- let msg = try XCTUnwrap ( message. value)
76- XCTAssertTrue ( msg. hasPrefix ( " 📦 foo just added a new package, Mock " ) , " was \( msg) " )
53+
54+ Current . shell. run = { @Sendable cmd, path in
55+ if cmd. description. hasSuffix ( " swift package dump-package " ) {
56+ return #"{ "name": "Mock", "products": [], "targets": [] }"#
57+ }
58+ return " "
7759 }
78-
79- // run stages again to simulate the cycle...
80- message. setValue ( nil )
81- try await reconcile ( client: app. client, database: app. db)
82- }
83-
84- try await withDependencies {
85- $0. date. now = . now. addingTimeInterval ( Constants . reIngestionDeadtime)
86- } operation: {
87- try await ingest ( client: app. client, database: app. db, mode: . limit( 10 ) )
88-
89- // MUT - analyze, triggering posts if any
90- try await Analyze . analyze ( client: app. client,
91- database: app. db,
92- mode: . limit( 10 ) )
93- }
94-
95- // validate - there are no new posts to send
96- XCTAssertNil ( message. value)
97-
98- // Now simulate receiving a package update: version 2.0.0
99- Current . git. getTags = { @Sendable _ in [ . tag( 2 , 0 , 0 ) ] }
100-
101- try await withDependencies {
102- // fast forward our clock by the deadtime interval again (*2) and re-ingest
103- $0. date. now = . now. addingTimeInterval ( Constants . reIngestionDeadtime * 2 )
104- } operation: {
105- try await ingest ( client: app. client, database: app. db, mode: . limit( 10 ) )
106- // MUT - analyze again
107- try await Analyze . analyze ( client: app. client,
108- database: app. db,
109- mode: . limit( 10 ) )
60+
61+ try await withDependencies {
62+ $0. date. now = . now
63+ $0. packageListRepository. fetchPackageList = { @Sendable _ in [ url. url] }
64+ $0. packageListRepository. fetchPackageDenyList = { @Sendable _ in [ ] }
65+ $0. packageListRepository. fetchCustomCollections = { @Sendable _ in [ ] }
66+ $0. packageListRepository. fetchCustomCollection = { @Sendable _, _ in [ ] }
67+ } operation: {
68+ // run first two processing steps
69+ try await reconcile ( client: app. client, database: app. db)
70+ try await ingest ( client: app. client, database: app. db, mode: . limit( 10 ) )
71+
72+ // MUT - analyze, triggering the post
73+ try await Analyze . analyze ( client: app. client,
74+ database: app. db,
75+ mode: . limit( 10 ) )
76+
77+ do {
78+ let msg = try XCTUnwrap ( message. value)
79+ XCTAssertTrue ( msg. hasPrefix ( " 📦 foo just added a new package, Mock " ) , " was \( msg) " )
80+ }
81+
82+ // run stages again to simulate the cycle...
83+ message. setValue ( nil )
84+ try await reconcile ( client: app. client, database: app. db)
85+ }
86+
87+ try await withDependencies {
88+ $0. date. now = . now. addingTimeInterval ( Constants . reIngestionDeadtime)
89+ } operation: {
90+ try await ingest ( client: app. client, database: app. db, mode: . limit( 10 ) )
91+
92+ // MUT - analyze, triggering posts if any
93+ try await Analyze . analyze ( client: app. client,
94+ database: app. db,
95+ mode: . limit( 10 ) )
96+ }
97+
98+ // validate - there are no new posts to send
99+ XCTAssertNil ( message. value)
100+
101+ // Now simulate receiving a package update: version 2.0.0
102+ Current . git. getTags = { @Sendable _ in [ . tag( 2 , 0 , 0 ) ] }
103+
104+ try await withDependencies {
105+ // fast forward our clock by the deadtime interval again (*2) and re-ingest
106+ $0. date. now = . now. addingTimeInterval ( Constants . reIngestionDeadtime * 2 )
107+ } operation: {
108+ try await ingest ( client: app. client, database: app. db, mode: . limit( 10 ) )
109+ // MUT - analyze again
110+ try await Analyze . analyze ( client: app. client,
111+ database: app. db,
112+ mode: . limit( 10 ) )
113+ }
114+
115+ // validate
116+ let msg = try XCTUnwrap ( message. value)
117+ XCTAssertTrue ( msg. hasPrefix ( " ⬆️ foo just released Mock v2.0.0 " ) , " was: \( msg) " )
110118 }
111-
112- // validate
113- let msg = try XCTUnwrap ( message. value)
114- XCTAssertTrue ( msg. hasPrefix ( " ⬆️ foo just released Mock v2.0.0 " ) , " was: \( msg) " )
115119 }
116120
117121}
0 commit comments