40 lines
1.6 KiB
Swift
40 lines
1.6 KiB
Swift
import Foundation
|
|
import CoreFoundation
|
|
|
|
@main
|
|
struct AuthContentSettingsCheck {
|
|
static func main() throws {
|
|
let receiptId = "synthetic-auth-receipt"
|
|
let cases: [(Bool, ContentType)] = [
|
|
(true, .ALL),
|
|
(true, .MALE),
|
|
(true, .FEMALE),
|
|
(false, .ALL)
|
|
]
|
|
|
|
for (isAdultContentVisible, contentType) in cases {
|
|
let request = AuthVerifyRequest(
|
|
receiptId: receiptId,
|
|
isAdultContentVisible: isAdultContentVisible,
|
|
contentType: contentType
|
|
)
|
|
let encoded = try JSONEncoder().encode(request)
|
|
guard let json = try JSONSerialization.jsonObject(with: encoded) as? [String: Any],
|
|
let encodedReceipt = json["receipt_id"] as? String,
|
|
let encodedVisibility = json["isAdultContentVisible"] as? NSNumber,
|
|
let encodedContentType = json["contentType"] as? String else {
|
|
assertionFailure("Expected receipt string, visibility bool and content type string")
|
|
return
|
|
}
|
|
|
|
assert(Set(json.keys) == Set(["receipt_id", "isAdultContentVisible", "contentType"]))
|
|
assert(encodedReceipt == receiptId)
|
|
assert(CFGetTypeID(encodedVisibility) == CFBooleanGetTypeID())
|
|
assert(encodedVisibility.boolValue == isAdultContentVisible)
|
|
assert(encodedContentType == contentType.rawValue)
|
|
}
|
|
|
|
print("PASS: AuthVerifyRequest exact JSON keys/types and ON ALL/MALE/FEMALE, OFF ALL (4 cases)")
|
|
}
|
|
}
|