Skip to content

Commit 7b47889

Browse files
committed
implement dbId dependency in portal tests
1 parent cb8ce7d commit 7b47889

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Tests/AppTests/PortalTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class PortalTests: AppTestCase {
9090
try withDependencies {
9191
let mock: @Sendable (_ req: Request, _ username: String, _ password: String) async throws -> CognitoAuthenticateResponse = { _, _, _ in throw SotoCognitoError.unauthorized(reason: "reason") }
9292
$0.cognito.authenticate = mock
93+
$0.environment.dbId = { nil }
9394
} operation: {
9495
try app.test(.POST, "login", beforeRequest: { req in try req.content.encode(["email": "testemail", "password": "testpassword"])
9596
}, afterResponse: { res in
@@ -102,6 +103,7 @@ class PortalTests: AppTestCase {
102103
try withDependencies {
103104
let mock: @Sendable (_ req: Request, _ username: String, _ password: String) async throws -> CognitoAuthenticateResponse = { _, _, _ in throw AWSClientError.accessDenied }
104105
$0.cognito.authenticate = mock
106+
$0.environment.dbId = { nil }
105107
} operation: {
106108
try app.test(.POST, "login", beforeRequest: { req in try req.content.encode(["email": "testemail", "password": "testpassword"])
107109
}, afterResponse: { res in
@@ -115,6 +117,7 @@ class PortalTests: AppTestCase {
115117
try withDependencies {
116118
let mock: @Sendable (_ req: Request, _ username: String, _ password: String) async throws -> CognitoAuthenticateResponse = { _, _, _ in throw SomeError() }
117119
$0.cognito.authenticate = mock
120+
$0.environment.dbId = { nil }
118121
} operation: {
119122
try app.test(.POST, "login", beforeRequest: { req in try req.content.encode(["email": "testemail", "password": "testpassword"])
120123
}, afterResponse: { res in
@@ -127,6 +130,7 @@ class PortalTests: AppTestCase {
127130
try withDependencies {
128131
let mock: @Sendable (_ req: Request, _ username: String, _ password: String) async throws -> Void = { _, _, _ in }
129132
$0.cognito.signup = mock
133+
$0.environment.dbId = { nil }
130134
} operation: {
131135
try app.test(.POST, "signup", beforeRequest: { req in try req.content.encode(["email": "testemail", "password": "testpassword"])
132136
}, afterResponse: { res in
@@ -140,6 +144,7 @@ class PortalTests: AppTestCase {
140144
try withDependencies {
141145
let mock: @Sendable (_ req: Request, _ username: String, _ password: String) async throws -> Void = { _, _, _ in throw AWSClientError.accessDenied }
142146
$0.cognito.signup = mock
147+
$0.environment.dbId = { nil }
143148
} operation: {
144149
try app.test(.POST, "signup", beforeRequest: { req in try req.content.encode(["email": "testemail", "password": "testpassword"])
145150
}, afterResponse: { res in
@@ -153,6 +158,7 @@ class PortalTests: AppTestCase {
153158
try withDependencies {
154159
let mock: @Sendable (_ req: Request, _ username: String, _ password: String) async throws -> Void = { _, _, _ in throw SomeError() }
155160
$0.cognito.signup = mock
161+
$0.environment.dbId = { nil }
156162
} operation: {
157163
try app.test(.POST, "signup") { res in
158164
XCTAssertTrue(res.body.string.contains("error"))
@@ -164,6 +170,7 @@ class PortalTests: AppTestCase {
164170
try withDependencies {
165171
let mock: @Sendable (_ req: Request, _ username: String, _ password: String, _ confirmationCode: String) async throws -> Void = { _, _, _, _ in }
166172
$0.cognito.resetPassword = mock
173+
$0.environment.dbId = { nil }
167174
} operation: {
168175
try app.test(.POST, "reset", beforeRequest: { req in try req.content.encode(["email": "testemail", "password": "testpassword", "confirmationCode": "123"])
169176
}, afterResponse: { res in
@@ -177,6 +184,7 @@ class PortalTests: AppTestCase {
177184
try withDependencies {
178185
let mock: @Sendable (_ req: Request, _ username: String, _ password: String, _ confirmationCode: String) async throws -> Void = { _, _, _, _ in throw AWSClientError.accessDenied }
179186
$0.cognito.resetPassword = mock
187+
$0.environment.dbId = { nil }
180188
} operation: {
181189
try app.test(.POST, "reset", beforeRequest: { req in try req.content.encode(["email": "testemail", "password": "testpassword", "confirmationCode": "123"])
182190
}, afterResponse: { res in
@@ -190,6 +198,7 @@ class PortalTests: AppTestCase {
190198
struct SomeError: Error {}
191199
let mock: @Sendable (_ req: Request, _ username: String, _ password: String, _ confirmationCode: String) async throws -> Void = { _, _, _, _ in throw SomeError() }
192200
$0.cognito.resetPassword = mock
201+
$0.environment.dbId = { nil }
193202
} operation: {
194203
try app.test(.POST, "reset", beforeRequest: { req in try req.content.encode(["email": "testemail", "password": "testpassword", "confirmationCode": "123"])
195204
}, afterResponse: { res in
@@ -202,6 +211,7 @@ class PortalTests: AppTestCase {
202211
try withDependencies {
203212
let mock: @Sendable (_ req: Request, _ username: String) async throws -> Void = { _, _ in }
204213
$0.cognito.forgotPassword = mock
214+
$0.environment.dbId = { nil }
205215
} operation: {
206216
try app.test(.POST, "forgot-password", beforeRequest: { req in try req.content.encode(["email": "testemail"])
207217
}, afterResponse: { res in
@@ -216,6 +226,7 @@ class PortalTests: AppTestCase {
216226
struct SomeError: Error {}
217227
let mock: @Sendable (_ req: Request, _ username: String) async throws -> Void = { _, _ in throw SomeError() }
218228
$0.cognito.forgotPassword = mock
229+
$0.environment.dbId = { nil }
219230
} operation: {
220231
try app.test(.POST, "forgot-password", beforeRequest: { req in try req.content.encode(["email": "testemail"])
221232
}, afterResponse: { res in
@@ -245,6 +256,7 @@ class PortalTests: AppTestCase {
245256
try withDependencies {
246257
let mock: @Sendable (_ req: Request, _ username: String, _ confirmationCode: String) async throws -> Void = { _, _, _ in }
247258
$0.cognito.confirmSignUp = mock
259+
$0.environment.dbId = { nil }
248260
} operation: {
249261
try app.test(.POST, "verify", beforeRequest: { req in try req.content.encode(["email": "testemail", "confirmationCode": "123"])
250262
}, afterResponse: { res in
@@ -258,6 +270,7 @@ class PortalTests: AppTestCase {
258270
try withDependencies {
259271
let mock: @Sendable (_ req: Request, _ username: String, _ confirmationCode: String) async throws -> Void = { _, _, _ in throw AWSClientError.accessDenied }
260272
$0.cognito.confirmSignUp = mock
273+
$0.environment.dbId = { nil }
261274
} operation: {
262275
try app.test(.POST, "verify", beforeRequest: { req in try req.content.encode(["email": "testemail", "confirmationCode": "123"])
263276
}, afterResponse: { res in
@@ -271,6 +284,7 @@ class PortalTests: AppTestCase {
271284
struct SomeError: Error {}
272285
let mock: @Sendable (_ req: Request, _ username: String, _ confirmationCode: String) async throws -> Void = { _, _, _ in throw SomeError() }
273286
$0.cognito.confirmSignUp = mock
287+
$0.environment.dbId = { nil }
274288
} operation: {
275289
try app.test(.POST, "verify", beforeRequest: { req in try req.content.encode(["email": "testemail", "confirmationCode": "123"])
276290
}, afterResponse: { res in
@@ -310,6 +324,7 @@ class PortalTests: AppTestCase {
310324
struct SomeError: Error {}
311325
let mock: @Sendable (_ req: Request) async throws -> Void = { _ in throw SomeError() }
312326
$0.cognito.deleteUser = mock
327+
$0.environment.dbId = { nil }
313328
} operation: {
314329
try app.test(.POST, "delete") { res in
315330
XCTAssertEqual(res.status, .internalServerError)

0 commit comments

Comments
 (0)