-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/cookies
- Loading branch information
Showing
20 changed files
with
226 additions
and
1 deletion.
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
5 changes: 4 additions & 1 deletion
5
Sources/Postie/Responses/ResponseBody/ResponseBody+DecodingStrategies.swift
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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
public extension ResponseBody { | ||
|
||
typealias OptionalContent = ResponseBodyWrapper<Body, OptionalContentStrategy> | ||
|
||
typealias Status200 = ResponseBodyWrapper<Body, ValidateStatus200BodyStrategy> | ||
typealias Status201 = ResponseBodyWrapper<Body, ValidateStatus201BodyStrategy> | ||
typealias Status303 = ResponseBodyWrapper<Body, ValidateStatus303BodyStrategy> | ||
} |
8 changes: 8 additions & 0 deletions
8
Sources/Postie/Responses/ResponseErrorBody/ResponseErrorBody+DecodingStrategies.swift
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
public extension ResponseErrorBody { | ||
typealias Status400 = ResponseErrorBodyWrapper<Body, ValidateStatus400ErrorBodyStrategy> | ||
typealias Status401 = ResponseErrorBodyWrapper<Body, ValidateStatus401ErrorBodyStrategy> | ||
typealias Status403 = ResponseErrorBodyWrapper<Body, ValidateStatus403ErrorBodyStrategy> | ||
typealias Status404 = ResponseErrorBodyWrapper<Body, ValidateStatus404ErrorBodyStrategy> | ||
typealias Status410 = ResponseErrorBodyWrapper<Body, ValidateStatus410ErrorBodyStrategy> | ||
typealias Status422 = ResponseErrorBodyWrapper<Body, ValidateStatus422ErrorBodyStrategy> | ||
} |
9 changes: 9 additions & 0 deletions
9
Sources/Postie/Strategies/Body/ValidateStatus200BodyStrategy.swift
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
public struct ValidateStatus200BodyStrategy: ResponseBodyDecodingStrategy { | ||
public static func allowsEmptyContent(for _: Int) -> Bool { | ||
return false | ||
} | ||
|
||
public static func validate(statusCode: Int) -> Bool { | ||
statusCode == HTTPStatusCode.ok.rawValue | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Sources/Postie/Strategies/Body/ValidateStatus201BodyStrategy.swift
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
public struct ValidateStatus201BodyStrategy: ResponseBodyDecodingStrategy { | ||
public static func allowsEmptyContent(for _: Int) -> Bool { | ||
return false | ||
} | ||
|
||
public static func validate(statusCode: Int) -> Bool { | ||
statusCode == HTTPStatusCode.created.rawValue | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Sources/Postie/Strategies/Body/ValidateStatus303BodyStrategy.swift
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
public struct ValidateStatus303BodyStrategy: ResponseBodyDecodingStrategy { | ||
public static func allowsEmptyContent(for _: Int) -> Bool { | ||
return true | ||
} | ||
|
||
public static func validate(statusCode: Int) -> Bool { | ||
statusCode == HTTPStatusCode.seeOther.rawValue | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
Sources/Postie/Strategies/Body/ValidateStatus400ErrorBodyStrategy.swift
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public struct ValidateStatus400ErrorBodyStrategy: ResponseErrorBodyDecodingStrategy { | ||
public static func isError(statusCode: Int) -> Bool { | ||
statusCode == HTTPStatusCode.badRequest.rawValue | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
Sources/Postie/Strategies/Body/ValidateStatus401ErrorBodyStrategy.swift
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public struct ValidateStatus401ErrorBodyStrategy: ResponseErrorBodyDecodingStrategy { | ||
public static func isError(statusCode: Int) -> Bool { | ||
statusCode == HTTPStatusCode.unauthorized.rawValue | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
Sources/Postie/Strategies/Body/ValidateStatus403ErrorBodyStrategy.swift
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public struct ValidateStatus403ErrorBodyStrategy: ResponseErrorBodyDecodingStrategy { | ||
public static func isError(statusCode: Int) -> Bool { | ||
statusCode == HTTPStatusCode.forbidden.rawValue | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
Sources/Postie/Strategies/Body/ValidateStatus404ErrorBodyStrategy.swift
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public struct ValidateStatus404ErrorBodyStrategy: ResponseErrorBodyDecodingStrategy { | ||
public static func isError(statusCode: Int) -> Bool { | ||
statusCode == HTTPStatusCode.notFound.rawValue | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
Sources/Postie/Strategies/Body/ValidateStatus410ErrorBodyStrategy.swift
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public struct ValidateStatus410ErrorBodyStrategy: ResponseErrorBodyDecodingStrategy { | ||
public static func isError(statusCode: Int) -> Bool { | ||
statusCode == HTTPStatusCode.gone.rawValue | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
Sources/Postie/Strategies/Body/ValidateStatus422ErrorBodyStrategy.swift
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public struct ValidateStatus422ErrorBodyStrategy: ResponseErrorBodyDecodingStrategy { | ||
public static func isError(statusCode: Int) -> Bool { | ||
statusCode == HTTPStatusCode.unprocessableEntity.rawValue | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Tests/PostieTests/Strategies/Body/ValidateStatus200BodyStrategyTests.swift
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
@testable import Postie | ||
import XCTest | ||
|
||
class ValidateStatus200BodyStrategyTests: XCTestCase { | ||
func testAllowsEmptyContent_statusIs200_shouldBeFalse() { | ||
XCTAssertFalse(ValidateStatus200BodyStrategy.allowsEmptyContent(for: 200)) | ||
} | ||
|
||
func testAllowsEmptyContent_statusIsNot200_shouldBeFalse() { | ||
XCTAssertFalse(ValidateStatus200BodyStrategy.allowsEmptyContent(for: 999)) | ||
} | ||
|
||
func testValidate_statusIs200_shouldBeTrue() { | ||
XCTAssertTrue(ValidateStatus200BodyStrategy.validate(statusCode: 200)) | ||
} | ||
|
||
func testValidate_statusIsNot200_shouldBeFalse() { | ||
XCTAssertFalse(ValidateStatus200BodyStrategy.validate(statusCode: 999)) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Tests/PostieTests/Strategies/Body/ValidateStatus201BodyStrategyTests.swift
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
@testable import Postie | ||
import XCTest | ||
|
||
class ValidateStatus201BodyStrategyTests: XCTestCase { | ||
func testAllowsEmptyContent_statusIs201_shouldBeFalse() { | ||
XCTAssertFalse(ValidateStatus201BodyStrategy.allowsEmptyContent(for: 201)) | ||
} | ||
|
||
func testAllowsEmptyContent_statusIsNot201_shouldBeFalse() { | ||
XCTAssertFalse(ValidateStatus201BodyStrategy.allowsEmptyContent(for: 999)) | ||
} | ||
|
||
func testValidate_statusIs201_shouldBeTrue() { | ||
XCTAssertTrue(ValidateStatus201BodyStrategy.validate(statusCode: 201)) | ||
} | ||
|
||
func testValidate_statusIsNot201_shouldBeFalse() { | ||
XCTAssertFalse(ValidateStatus201BodyStrategy.validate(statusCode: 999)) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Tests/PostieTests/Strategies/Body/ValidateStatus400ErrorBodyStrategyTests.swift
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@testable import Postie | ||
import XCTest | ||
|
||
class ValidateStatus400ErrorBodyStrategyTests: XCTestCase { | ||
func testIsError_statusIs400_shouldBeTrue() { | ||
XCTAssertTrue(ValidateStatus400ErrorBodyStrategy.isError(statusCode: 400)) | ||
} | ||
|
||
func testIsError_statusIsNot400_shouldBeFalse() { | ||
XCTAssertFalse(ValidateStatus400ErrorBodyStrategy.isError(statusCode: 999)) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Tests/PostieTests/Strategies/Body/ValidateStatus401ErrorBodyStrategyTests.swift
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@testable import Postie | ||
import XCTest | ||
|
||
class ValidateStatus401ErrorBodyStrategyTests: XCTestCase { | ||
func testIsError_statusIs401_shouldBeTrue() { | ||
XCTAssertTrue(ValidateStatus401ErrorBodyStrategy.isError(statusCode: 401)) | ||
} | ||
|
||
func testIsError_statusIsNot401_shouldBeFalse() { | ||
XCTAssertFalse(ValidateStatus401ErrorBodyStrategy.isError(statusCode: 999)) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Tests/PostieTests/Strategies/Body/ValidateStatus403ErrorBodyStrategyTests.swift
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@testable import Postie | ||
import XCTest | ||
|
||
class ValidateStatus403ErrorBodyStrategyTests: XCTestCase { | ||
func testIsError_statusIs403_shouldBeTrue() { | ||
XCTAssertTrue(ValidateStatus403ErrorBodyStrategy.isError(statusCode: 403)) | ||
} | ||
|
||
func testIsError_statusIsNot403_shouldBeFalse() { | ||
XCTAssertFalse(ValidateStatus403ErrorBodyStrategy.isError(statusCode: 999)) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Tests/PostieTests/Strategies/Body/ValidateStatus404ErrorBodyStrategyTests.swift
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@testable import Postie | ||
import XCTest | ||
|
||
class ValidateStatus404ErrorBodyStrategyTests: XCTestCase { | ||
func testIsError_statusIs404_shouldBeTrue() { | ||
XCTAssertTrue(ValidateStatus404ErrorBodyStrategy.isError(statusCode: 404)) | ||
} | ||
|
||
func testIsError_statusIsNot404_shouldBeFalse() { | ||
XCTAssertFalse(ValidateStatus404ErrorBodyStrategy.isError(statusCode: 999)) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Tests/PostieTests/Strategies/Body/ValidateStatus410ErrorBodyStrategyTests.swift
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@testable import Postie | ||
import XCTest | ||
|
||
class ValidateStatus410ErrorBodyStrategyTests: XCTestCase { | ||
func testIsError_statusIs410_shouldBeTrue() { | ||
XCTAssertTrue(ValidateStatus410ErrorBodyStrategy.isError(statusCode: 410)) | ||
} | ||
|
||
func testIsError_statusIsNot410_shouldBeFalse() { | ||
XCTAssertFalse(ValidateStatus410ErrorBodyStrategy.isError(statusCode: 999)) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Tests/PostieTests/Strategies/Body/ValidateStatus422ErrorBodyStrategyTests.swift
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@testable import Postie | ||
import XCTest | ||
|
||
class ValidateStatus422ErrorBodyStrategyTests: XCTestCase { | ||
func testIsError_statusIs422_shouldBeTrue() { | ||
XCTAssertTrue(ValidateStatus422ErrorBodyStrategy.isError(statusCode: 422)) | ||
} | ||
|
||
func testIsError_statusIsNot422_shouldBeFalse() { | ||
XCTAssertFalse(ValidateStatus422ErrorBodyStrategy.isError(statusCode: 999)) | ||
} | ||
} |