Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis committed Jan 25, 2024
1 parent a2e8918 commit 7d0415f
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-composable-architecture",
"state" : {
"revision" : "3568f01377c6c668aad40d066acf97ce670a1dad",
"version" : "1.5.6"
"revision" : "ae491c9e3f66631e72d58db8bb4c27dfc3d3afd4",
"version" : "1.6.0"
}
},
{
Expand Down
27 changes: 20 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ var package = Package(
"SiteMiddleware",
.product(name: "HttpPipeline", package: "swift-web"),
.product(name: "HttpPipelineTestSupport", package: "swift-web"),
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "Prelude", package: "swift-prelude"),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
],
Expand Down Expand Up @@ -158,6 +159,7 @@ var package = Package(
"FirstPartyMocks",
"SharedModels",
"TestHelpers",
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "Overture", package: "swift-overture"),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
],
Expand Down Expand Up @@ -396,6 +398,7 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"FirstPartyMocks",
"TestHelpers",
.product(name: "CustomDump", package: "swift-custom-dump"),
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "Overture", package: "swift-overture"),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
],
Expand Down Expand Up @@ -1027,6 +1030,7 @@ package.targets.append(contentsOf: [
"AppSiteAssociationMiddleware",
"SiteMiddleware",
.product(name: "HttpPipelineTestSupport", package: "swift-web"),
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
]
),
Expand Down Expand Up @@ -1055,6 +1059,7 @@ package.targets.append(contentsOf: [
.product(name: "CustomDump", package: "swift-custom-dump"),
.product(name: "HttpPipeline", package: "swift-web"),
.product(name: "HttpPipelineTestSupport", package: "swift-web"),
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
],
exclude: ["__Snapshots__"]
Expand Down Expand Up @@ -1118,6 +1123,7 @@ package.targets.append(contentsOf: [
"DemoMiddleware",
"SiteMiddleware",
.product(name: "HttpPipelineTestSupport", package: "swift-web"),
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
]
),
Expand Down Expand Up @@ -1146,6 +1152,7 @@ package.targets.append(contentsOf: [
"SiteMiddleware",
.product(name: "CustomDump", package: "swift-custom-dump"),
.product(name: "HttpPipelineTestSupport", package: "swift-web"),
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
],
exclude: ["__Snapshots__"]
Expand Down Expand Up @@ -1190,6 +1197,7 @@ package.targets.append(contentsOf: [
.product(name: "Either", package: "swift-prelude"),
.product(name: "HttpPipeline", package: "swift-web"),
.product(name: "HttpPipelineTestSupport", package: "swift-web"),
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "Overture", package: "swift-overture"),
.product(name: "Prelude", package: "swift-prelude"),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
Expand Down Expand Up @@ -1244,13 +1252,6 @@ package.targets.append(contentsOf: [
.product(name: "HttpPipeline", package: "swift-web"),
]
),
.target(
name: "ServerTestHelpers",
dependencies: [
.product(name: "Either", package: "swift-prelude"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
]
),
.testTarget(
name: "ServerConfigMiddlewareTests",
dependencies: [
Expand All @@ -1259,9 +1260,17 @@ package.targets.append(contentsOf: [
.product(name: "Either", package: "swift-prelude"),
.product(name: "HttpPipeline", package: "swift-web"),
.product(name: "HttpPipelineTestSupport", package: "swift-web"),
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "Prelude", package: "swift-prelude"),
]
),
.target(
name: "ServerTestHelpers",
dependencies: [
.product(name: "Either", package: "swift-prelude"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
]
),
.target(
name: "ShareGameMiddleware",
dependencies: [
Expand All @@ -1280,6 +1289,7 @@ package.targets.append(contentsOf: [
"SiteMiddleware",
"TestHelpers",
.product(name: "HttpPipelineTestSupport", package: "swift-web"),
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
],
exclude: ["__Snapshots__"]
Expand Down Expand Up @@ -1315,6 +1325,7 @@ package.targets.append(contentsOf: [
"SiteMiddleware",
"TestHelpers",
.product(name: "HttpPipelineTestSupport", package: "swift-web"),
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
],
exclude: ["__Snapshots__"]
Expand All @@ -1332,6 +1343,7 @@ package.targets.append(contentsOf: [
name: "SnsClientTests",
dependencies: [
"SnsClient",
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
]
),
Expand Down Expand Up @@ -1361,6 +1373,7 @@ package.targets.append(contentsOf: [
"SiteMiddleware",
.product(name: "CustomDump", package: "swift-custom-dump"),
.product(name: "HttpPipelineTestSupport", package: "swift-web"),
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
]
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import AppSiteAssociationMiddleware
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
import HttpPipeline
import HttpPipelineTestSupport
import InlineSnapshotTesting
import Prelude
import ServerRouter
import SharedModels
import SiteMiddleware
import SnapshotTesting
import XCTest

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

class AppSiteAssociationMiddlewareTests: XCTestCase {
func testBasics() throws {
let request = URLRequest(url: URL(string: "/.well-known/apple-app-site-association")!)
let middleware = siteMiddleware(environment: .testValue)
let result = middleware(connection(from: request)).perform()

_assertInlineSnapshot(matching: result, as: .conn, with: #"""
assertInlineSnapshot(of: result, as: .conn) {
#"""
GET /.well-known/apple-app-site-association
200 OK
Expand Down Expand Up @@ -54,6 +56,8 @@ class AppSiteAssociationMiddlewareTests: XCTestCase {
]
}
}
"""#)
"""#
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import CustomDump
import DatabaseClient
import Either
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
import FirstPartyMocks
import Foundation
import HttpPipeline
import HttpPipelineTestSupport
import InlineSnapshotTesting
import MailgunClient
import Overture
import SharedModels
import SnapshotTesting
import XCTest

@testable import SiteMiddleware

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

class DailyChallengeMiddlewareTests: XCTestCase {
let encoder = update(JSONEncoder()) {
$0.dateEncodingStrategy = .secondsSince1970
Expand All @@ -24,7 +25,7 @@ class DailyChallengeMiddlewareTests: XCTestCase {

override func setUp() {
super.setUp()
// SnapshotTesting.isRecording=true
// SnapshotTesting.isRecording=true
}

func testToday_NotYetPlayed() {
Expand Down Expand Up @@ -178,10 +179,8 @@ class DailyChallengeMiddlewareTests: XCTestCase {
)
)
request.allHTTPHeaderFields = [
"X-Signature": (
request.httpBody! + Data("----SECRET_DEADBEEF----1234567890".utf8)
)
.base64EncodedString()
"X-Signature": (request.httpBody! + Data("----SECRET_DEADBEEF----1234567890".utf8))
.base64EncodedString()
]

var environment = ServerEnvironment.testValue
Expand Down Expand Up @@ -237,7 +236,8 @@ class DailyChallengeMiddlewareTests: XCTestCase {
let middleware = siteMiddleware(environment: environment)
let result = middleware(connection(from: request)).perform()

_assertInlineSnapshot(matching: result, as: .conn, with: """
assertInlineSnapshot(of: result, as: .conn) {
"""
POST /api/games?accessToken=deadbeef-dead-beef-dead-beefdeadbeef&timestamp=1234567890
X-Signature: ewogICJnYW1lQ29udGV4dCIgOiB7CiAgICAiZGFpbHlDaGFsbGVuZ2VJZCIgOiAiREVBREJFRUYtREVBRC1CRUVGLURFQUQtREExMTdDNEExMTMyIgogIH0sCiAgIm1vdmVzIiA6IFsKICAgIHsKICAgICAgInBsYXllZEF0IiA6IDEyMzQ1Njc4OTAuNSwKICAgICAgInNjb3JlIiA6IDI3LAogICAgICAidHlwZSIgOiB7CiAgICAgICAgInBsYXllZFdvcmQiIDogWwogICAgICAgICAgewogICAgICAgICAgICAiaW5kZXgiIDogewogICAgICAgICAgICAgICJ4IiA6IDIsCiAgICAgICAgICAgICAgInkiIDogMiwKICAgICAgICAgICAgICAieiIgOiAyCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgICJzaWRlIiA6IDAKICAgICAgICAgIH0sCiAgICAgICAgICB7CiAgICAgICAgICAgICJpbmRleCIgOiB7CiAgICAgICAgICAgICAgIngiIDogMiwKICAgICAgICAgICAgICAieSIgOiAyLAogICAgICAgICAgICAgICJ6IiA6IDIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgInNpZGUiIDogMQogICAgICAgICAgfSwKICAgICAgICAgIHsKICAgICAgICAgICAgImluZGV4IiA6IHsKICAgICAgICAgICAgICAieCIgOiAyLAogICAgICAgICAgICAgICJ5IiA6IDIsCiAgICAgICAgICAgICAgInoiIDogMgogICAgICAgICAgICB9LAogICAgICAgICAgICAic2lkZSIgOiAyCiAgICAgICAgICB9CiAgICAgICAgXQogICAgICB9CiAgICB9CiAgXQp9LS0tLVNFQ1JFVF9ERUFEQkVFRi0tLS0xMjM0NTY3ODkw
Expand Down Expand Up @@ -280,7 +280,7 @@ class DailyChallengeMiddlewareTests: XCTestCase {
}
]
}
200 OK
Content-Length: 107
Content-Type: application/json
Expand All @@ -290,7 +290,7 @@ class DailyChallengeMiddlewareTests: XCTestCase {
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block
{
"dailyChallenge" : {
"outOf" : 100,
Expand All @@ -299,8 +299,9 @@ class DailyChallengeMiddlewareTests: XCTestCase {
"started" : false
}
}
"""
)
}

XCTAssertNoDifference(
submittedScore,
Expand Down Expand Up @@ -352,10 +353,8 @@ class DailyChallengeMiddlewareTests: XCTestCase {
)
)
request.allHTTPHeaderFields = [
"X-Signature": (
request.httpBody! + Data("----SECRET_DEADBEEF----1234567890".utf8)
)
.base64EncodedString()
"X-Signature": (request.httpBody! + Data("----SECRET_DEADBEEF----1234567890".utf8))
.base64EncodedString()
]

var environment = ServerEnvironment.testValue
Expand All @@ -382,10 +381,11 @@ class DailyChallengeMiddlewareTests: XCTestCase {

// NB: Linux's localized message is different
#if !os(Linux)
_assertInlineSnapshot(matching: result, as: .conn, with: #"""
assertInlineSnapshot(of: result, as: .conn) {
#"""
POST /api/games?accessToken=deadbeef-dead-beef-dead-beefdeadbeef&timestamp=1234567890
X-Signature: ewogICJnYW1lQ29udGV4dCIgOiB7CiAgICAiZGFpbHlDaGFsbGVuZ2VJZCIgOiAiREVBREJFRUYtREVBRC1CRUVGLURFQUQtREExMTdDNEExMTMyIgogIH0sCiAgIm1vdmVzIiA6IFsKICAgIHsKICAgICAgInBsYXllZEF0IiA6IDEyMzQ1Njc4OTAsCiAgICAgICJzY29yZSIgOiAxMDAwLAogICAgICAidHlwZSIgOiB7CiAgICAgICAgInBsYXllZFdvcmQiIDogWwogICAgICAgICAgewogICAgICAgICAgICAiaW5kZXgiIDogewogICAgICAgICAgICAgICJ4IiA6IDAsCiAgICAgICAgICAgICAgInkiIDogMCwKICAgICAgICAgICAgICAieiIgOiAwCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgICJzaWRlIiA6IDEKICAgICAgICAgIH0sCiAgICAgICAgICB7CiAgICAgICAgICAgICJpbmRleCIgOiB7CiAgICAgICAgICAgICAgIngiIDogMCwKICAgICAgICAgICAgICAieSIgOiAwLAogICAgICAgICAgICAgICJ6IiA6IDAKICAgICAgICAgICAgfSwKICAgICAgICAgICAgInNpZGUiIDogMgogICAgICAgICAgfSwKICAgICAgICAgIHsKICAgICAgICAgICAgImluZGV4IiA6IHsKICAgICAgICAgICAgICAieCIgOiAxLAogICAgICAgICAgICAgICJ5IiA6IDAsCiAgICAgICAgICAgICAgInoiIDogMAogICAgICAgICAgICB9LAogICAgICAgICAgICAic2lkZSIgOiAyCiAgICAgICAgICB9CiAgICAgICAgXQogICAgICB9CiAgICB9CiAgXQp9LS0tLVNFQ1JFVF9ERUFEQkVFRi0tLS0xMjM0NTY3ODkw
{
"gameContext" : {
"dailyChallengeId" : "DEADBEEF-DEAD-BEEF-DEAD-DA117C4A1132"
Expand Down Expand Up @@ -425,7 +425,7 @@ class DailyChallengeMiddlewareTests: XCTestCase {
}
]
}
400 Bad Request
Content-Length: 492
Content-Type: application/json
Expand All @@ -435,15 +435,16 @@ class DailyChallengeMiddlewareTests: XCTestCase {
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block
{
"errorDump" : "▿ SharedModels.ApiError\n - errorDump: \"- LeaderboardMiddleware.VerificationFailed\\n\"\n - file: \"LeaderboardMiddleware\/SubmitGameMiddleware.swift\"\n - line: 109\n - message: \"The operation couldn’t be completed. (LeaderboardMiddleware.VerificationFailed error 1.)\"\n",
"file" : "LeaderboardMiddleware\/SubmitGameMiddleware.swift",
"line" : 202,
"message" : "The operation couldn’t be completed. (LeaderboardMiddleware.VerificationFailed error 1.)"
}
"""#
)
}
#endif
}

Expand Down Expand Up @@ -488,9 +489,10 @@ class DailyChallengeMiddlewareTests: XCTestCase {
let middleware = siteMiddleware(environment: environment)
let result = middleware(connection(from: request)).perform()

_assertInlineSnapshot(matching: result, as: .conn, with: """
assertInlineSnapshot(of: result, as: .conn) {
"""
GET /api/daily-challenges/results?accessToken=deadbeef-dead-beef-dead-beefdeadbeef&gameMode=unlimited&language=en
200 OK
Content-Length: 471
Content-Type: application/json
Expand All @@ -500,7 +502,7 @@ class DailyChallengeMiddlewareTests: XCTestCase {
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block
{
"results" : [
{
Expand All @@ -523,7 +525,8 @@ class DailyChallengeMiddlewareTests: XCTestCase {
}
]
}
"""
)
}
}
}
8 changes: 5 additions & 3 deletions Tests/DemoMiddlewareTests/DemoMiddlewareTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import Foundation
#endif
import HttpPipeline
import HttpPipelineTestSupport
import InlineSnapshotTesting
import Overture
import Prelude
import ServerRouter
import SharedModels
import SiteMiddleware
import SnapshotTesting
import XCTest

class DemoMiddlewareTests: XCTestCase {
Expand Down Expand Up @@ -41,7 +41,8 @@ class DemoMiddlewareTests: XCTestCase {
let middleware = siteMiddleware(environment: environment)
let result = middleware(connection(from: request)).perform()

_assertInlineSnapshot(matching: result, as: .conn, with: """
assertInlineSnapshot(of: result, as: .conn) {
"""
POST /demo/games
{"gameMode": "timed", "score": 1000}
Expand Down Expand Up @@ -72,7 +73,8 @@ class DemoMiddlewareTests: XCTestCase {
}
}
}
"""
)
}
}
}
Loading

0 comments on commit 7d0415f

Please sign in to comment.