This repository has been archived by the owner on Apr 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0c97d9
commit 802dfe0
Showing
2 changed files
with
93 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,10 @@ class SanitizedTests: XCTestCase { | |
("testPermitted", testPermitted), | ||
("testEmptyPermitted", testEmptyPermitted), | ||
] | ||
|
||
|
||
|
||
// MARK: - Extraction. | ||
|
||
func testBasic() { | ||
let request = buildRequest(body: [ | ||
"id": 1, | ||
|
@@ -28,14 +31,71 @@ class SanitizedTests: XCTestCase { | |
XCTAssertEqual(model.email, "[email protected]") | ||
} | ||
} | ||
|
||
|
||
|
||
func testBasicFailed() { | ||
let request = buildInvalidRequest() | ||
expect(toThrow: Abort.badRequest) { | ||
let _: TestModel = try request.extractModel() | ||
} | ||
} | ||
|
||
|
||
|
||
// MARK: - Injection. | ||
|
||
func testInjectingNewKeys() { | ||
let request = buildRequest(body: [ | ||
"id": 1, | ||
"name": "Brett" | ||
]) | ||
|
||
expectNoThrow() { | ||
let model: TestModel = try request.extractModel( | ||
injecting: ["email": "[email protected]"] | ||
) | ||
XCTAssertNil(model.id) | ||
XCTAssertEqual(model.name, "Brett") | ||
XCTAssertEqual(model.email, "[email protected]") | ||
} | ||
} | ||
|
||
func testOverridingKeys() { | ||
let request = buildRequest(body: [ | ||
"id": 1, | ||
"name": "Brett", | ||
"email": "[email protected]" | ||
]) | ||
|
||
expectNoThrow() { | ||
let model: TestModel = try request.extractModel( | ||
injecting: ["email": "[email protected]"] | ||
) | ||
XCTAssertNil(model.id) | ||
XCTAssertEqual(model.name, "Brett") | ||
XCTAssertEqual(model.email, "[email protected]") | ||
} | ||
} | ||
|
||
func testInjectingSanitizedKeys() { | ||
let request = buildRequest(body: [ | ||
"id": 1, | ||
"name": "Brett", | ||
"email": "[email protected]" | ||
]) | ||
|
||
expectNoThrow() { | ||
let model: TestModel = try request.extractModel( | ||
injecting: ["id": 1337] | ||
) | ||
XCTAssertNil(model.id) | ||
XCTAssertEqual(model.name, "Brett") | ||
XCTAssertEqual(model.email, "[email protected]") | ||
} | ||
} | ||
|
||
|
||
// MARK: - Validation. | ||
|
||
func testPreValidateError() { | ||
let request = buildRequest(body: [ | ||
"email": "[email protected]" | ||
|
@@ -62,7 +122,10 @@ class SanitizedTests: XCTestCase { | |
let _: TestModel = try request.extractModel() | ||
} | ||
} | ||
|
||
|
||
|
||
// MARK: - Permitted fields. | ||
|
||
func testPermitted() { | ||
let json = JSON([ | ||
"id": 1, | ||
|
@@ -88,7 +151,10 @@ class SanitizedTests: XCTestCase { | |
XCTAssertNil(result["name"]) | ||
XCTAssertNil(result["email"]) | ||
} | ||
|
||
|
||
|
||
// MARK: - Patching. | ||
|
||
func testPatchBasic() { | ||
let model = try! TestModel(node: [ | ||
"id": 15, | ||
|