Skip to content

Commit d3a0823

Browse files
committed
Convert PlausibleTests
1 parent b82f729 commit d3a0823

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

Tests/AppTests/PlausibleTests.swift

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,60 +12,61 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import XCTest
15+
import Foundation
1616

1717
@testable import App
1818

1919
import Dependencies
20+
import Testing
2021

2122

22-
final class PlausibleTests: XCTestCase {
23+
@Suite struct PlausibleTests {
2324

24-
func test_User_identifier() throws {
25-
XCTAssertEqual(User.api(for: "token"), .init(name: "api", identifier: "3c469e9d"))
25+
@Test func User_identifier() throws {
26+
#expect(User.api(for: "token") == .init(name: "api", identifier: "3c469e9d"))
2627
}
2728

28-
func test_props() throws {
29-
XCTAssertEqual(Plausible.props(for: nil), ["user": "none"])
30-
XCTAssertEqual(Plausible.props(for: .init(name: "api", identifier: "foo")), ["user": "foo"])
29+
@Test func props() throws {
30+
#expect(Plausible.props(for: nil) == ["user": "none"])
31+
#expect(Plausible.props(for: .init(name: "api", identifier: "foo")) == ["user": "foo"])
3132
}
3233

33-
func test_postEvent_anonymous() async throws {
34+
@Test func postEvent_anonymous() async throws {
3435
let called = ActorIsolated(false)
3536
try await withDependencies {
3637
$0.environment.plausibleBackendReportingSiteID = { "foo.bar" }
3738
$0.httpClient.post = { @Sendable _, _, body in
3839
await called.withValue { $0 = true }
3940
// validate
40-
let body = try XCTUnwrap(body)
41-
XCTAssertEqual(try? JSONDecoder().decode(Plausible.Event.self, from: body),
42-
.init(name: .pageview,
43-
url: "https://foo.bar/api/search",
44-
domain: "foo.bar",
45-
props: ["user": "none"]))
41+
let body = try #require(body)
42+
#expect(try JSONDecoder().decode(Plausible.Event.self, from: body)
43+
== .init(name: .pageview,
44+
url: "https://foo.bar/api/search",
45+
domain: "foo.bar",
46+
props: ["user": "none"]))
4647
return .ok
4748
}
4849
} operation: {
4950
// MUT
5051
_ = try await Plausible.postEvent(kind: .pageview, path: .search, user: nil)
5152

52-
await called.withValue { XCTAssertTrue($0) }
53+
await called.withValue { #expect($0) }
5354
}
5455
}
5556

56-
func test_postEvent_package() async throws {
57+
@Test func postEvent_package() async throws {
5758
let called = ActorIsolated(false)
5859
try await withDependencies {
5960
$0.environment.plausibleBackendReportingSiteID = { "foo.bar" }
6061
$0.httpClient.post = { @Sendable _, _, body in
6162
await called.withValue { $0 = true }
6263
// validate
63-
let body = try XCTUnwrap(body)
64-
XCTAssertEqual(try? JSONDecoder().decode(Plausible.Event.self, from: body),
65-
.init(name: .pageview,
66-
url: "https://foo.bar/api/packages/{owner}/{repository}",
67-
domain: "foo.bar",
68-
props: ["user": "3c469e9d"]))
64+
let body = try #require(body)
65+
#expect(try JSONDecoder().decode(Plausible.Event.self, from: body)
66+
== .init(name: .pageview,
67+
url: "https://foo.bar/api/packages/{owner}/{repository}",
68+
domain: "foo.bar",
69+
props: ["user": "3c469e9d"]))
6970
return .ok
7071
}
7172
} operation: {
@@ -74,7 +75,7 @@ final class PlausibleTests: XCTestCase {
7475
// MUT
7576
_ = try await Plausible.postEvent(kind: .pageview, path: .package, user: user)
7677

77-
await called.withValue { XCTAssertTrue($0) }
78+
await called.withValue { #expect($0) }
7879
}
7980
}
8081
}

0 commit comments

Comments
 (0)