@@ -32,6 +32,7 @@ class ApiTests: AppTestCase {
3232 func test_search_noQuery( ) throws {
3333 try withDependencies {
3434 $0. environment. apiSigningKey = { " secret " }
35+ $0. httpClient. postPlausibleEvent = App . HTTPClient. noop
3536 } operation: {
3637 // MUT
3738 try app. test ( . GET, " api/search " ,
@@ -48,8 +49,12 @@ class ApiTests: AppTestCase {
4849 }
4950
5051 func test_search_basic_param( ) async throws {
52+ let event = App . ActorIsolated< TestEvent?> ( nil )
5153 try await withDependencies {
5254 $0. environment. apiSigningKey = { " secret " }
55+ $0. httpClient. postPlausibleEvent = { @Sendable kind, path, _ in
56+ await event. setValue ( . init( kind: kind, path: path) )
57+ }
5358 } operation: {
5459 let p1 = Package ( id: . id0, url: " 1 " )
5560 try await p1. save ( on: app. db)
@@ -69,11 +74,6 @@ class ApiTests: AppTestCase {
6974 try await Version ( package : p2, packageName: " Bar " , reference: . branch( " main " ) ) . save ( on: app. db)
7075 try await Search . refresh ( on: app. db)
7176
72- let event = App . ActorIsolated< TestEvent?> ( nil )
73- Current . postPlausibleEvent = { @Sendable _, kind, path, _ in
74- await event. setValue ( . init( kind: kind, path: path) )
75- }
76-
7777 // MUT
7878 try await app. test ( . GET, " api/search?query=foo%20bar " ,
7979 headers: . bearerApplicationJSON( try . apiToken( secretKey: " secret " , tier: . tier1) ) ,
@@ -765,6 +765,7 @@ class ApiTests: AppTestCase {
765765 }
766766
767767 func test_get_badge( ) async throws {
768+ // sas 2024-12-20: Badges are not reporting plausbile events, because they triggered way too many events. (This is an old changes, just adding this comment today as I'm removing the old, commented out test remnants we still had in place.)
768769 // setup
769770 let owner = " owner "
770771 let repo = " repo "
@@ -782,11 +783,6 @@ class ApiTests: AppTestCase {
782783 try await Build ( version: v, platform: . macosXcodebuild, status: . ok, swiftVersion: . v1)
783784 . save ( on: app. db)
784785
785- let event = App . ActorIsolated< TestEvent?> ( nil )
786- Current . postPlausibleEvent = { @Sendable _, kind, path, _ in
787- await event. setValue ( . init( kind: kind, path: path) )
788- }
789-
790786 // MUT - swift versions
791787 try await app. test (
792788 . GET,
@@ -822,21 +818,20 @@ class ApiTests: AppTestCase {
822818 XCTAssertEqual ( badge. cacheSeconds, 6 * 3600 )
823819 XCTAssertNotNil ( badge. logoSvg)
824820 } )
825-
826- // ensure API event has been reported
827- // API reporting for badges is currently disabled, because it is very noisy
828- // await event.withValue {
829- // XCTAssertEqual($0, .some(.init(kind: .pageview, path: .badge)))
830- // }
831821 }
832822
833823 func test_package_collections_owner( ) async throws {
834824 try XCTSkipIf ( !isRunningInCI && EnvironmentClient . liveValue. collectionSigningPrivateKey ( ) == nil , " Skip test for local user due to unset COLLECTION_SIGNING_PRIVATE_KEY env variable " )
825+
826+ let event = App . ActorIsolated< TestEvent?> ( nil )
835827 try await withDependencies {
836828 $0. date. now = . t0
837829 $0. environment. apiSigningKey = { " secret " }
838830 $0. environment. collectionSigningCertificateChain = EnvironmentClient . liveValue. collectionSigningCertificateChain
839831 $0. environment. collectionSigningPrivateKey = EnvironmentClient . liveValue. collectionSigningPrivateKey
832+ $0. httpClient. postPlausibleEvent = { @Sendable kind, path, _ in
833+ await event. setValue ( . init( kind: kind, path: path) )
834+ }
840835 } operation: {
841836 // setup
842837 let p1 = Package ( id: . id1, url: " 1 " )
@@ -855,11 +850,6 @@ class ApiTests: AppTestCase {
855850 try await Product ( version: v, type: . library( . automatic) , name: " lib " )
856851 . save ( on: app. db)
857852
858- let event = App . ActorIsolated< TestEvent?> ( nil )
859- Current . postPlausibleEvent = { @Sendable _, kind, path, _ in
860- await event. setValue ( . init( kind: kind, path: path) )
861- }
862-
863853 do { // MUT
864854 let body : ByteBuffer = . init( string: """
865855 {
@@ -901,12 +891,14 @@ class ApiTests: AppTestCase {
901891
902892 func test_package_collections_packageURLs( ) async throws {
903893 try XCTSkipIf ( !isRunningInCI && EnvironmentClient . liveValue. collectionSigningPrivateKey ( ) == nil , " Skip test for local user due to unset COLLECTION_SIGNING_PRIVATE_KEY env variable " )
894+
904895 let refDate = Date ( timeIntervalSince1970: 0 )
905896 try await withDependencies {
906897 $0. date. now = refDate
907898 $0. environment. apiSigningKey = { " secret " }
908899 $0. environment. collectionSigningCertificateChain = EnvironmentClient . liveValue. collectionSigningCertificateChain
909900 $0. environment. collectionSigningPrivateKey = EnvironmentClient . liveValue. collectionSigningPrivateKey
901+ $0. httpClient. postPlausibleEvent = App . HTTPClient. noop
910902 } operation: {
911903 // setup
912904 let p1 = Package ( id: UUID ( uuidString: " 442cf59f-0135-4d08-be00-bc9a7cebabd3 " ) !,
@@ -1049,6 +1041,7 @@ class ApiTests: AppTestCase {
10491041 try await withDependencies {
10501042 $0. environment. apiSigningKey = { " secret " }
10511043 $0. environment. dbId = { nil }
1044+ $0. httpClient. postPlausibleEvent = App . HTTPClient. noop
10521045 } operation: {
10531046 let owner = " owner "
10541047 let repo = " repo "
@@ -1112,6 +1105,7 @@ class ApiTests: AppTestCase {
11121105 func test_dependencies_get( ) async throws {
11131106 try await withDependencies {
11141107 $0. environment. apiSigningKey = { " secret " }
1108+ $0. httpClient. postPlausibleEvent = App . HTTPClient. noop
11151109 } operation: {
11161110 let pkg = try await savePackage ( on: app. db, id: . id0, " http://github.com/foo/bar " )
11171111 try await Repository ( package : pkg,
0 commit comments