Skip to content

Commit

Permalink
Updated ModelTests test cases to pass
Browse files Browse the repository at this point in the history
Test cases where modified where the expected behaviour was changed or the test was itself broken.
  • Loading branch information
calebkleveter committed Jan 23, 2019
1 parent 981f408 commit 3583185
Show file tree
Hide file tree
Showing 60 changed files with 223 additions and 213 deletions.
2 changes: 1 addition & 1 deletion Tests/ControllerTests/BillingAgreementsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class BillingAgreementsTests: XCTestCase {
guard let plan = try app.make(BillingPlans.self).list(state: .active).wait().plans?.first else {
throw Abort(.internalServerError, reason: "No billing plan found")
}
guard let id = plan.id else {
guard let id = plan.id.value else {
throw Abort(.internalServerError, reason: "Billing plan missing ID")
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/ControllerTests/BillingPlansTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class BillingPlansTests: XCTestCase {

let plans = try! self.app.make(BillingPlans.self)
let list = try! plans.list(parameters: QueryParamaters(totalCountRequired: true)).wait()
self.id = list.plans?.first?.id
self.id = list.plans?.first?.id.value
}

func testServiceExists()throws {
Expand Down Expand Up @@ -85,7 +85,7 @@ final class BillingPlansTests: XCTestCase {

let details = try plans.details(plan: id).wait()

XCTAssertEqual(details.id, id)
XCTAssert(details.id.value == id)
}

func testSetStateHelper()throws {
Expand Down
6 changes: 3 additions & 3 deletions Tests/ControllerTests/InvoicesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ final class InvoicesTests: XCTestCase {

let updated = try invoices.update(invoice: id, with: invoice).wait()

XCTAssertEqual(invoice.date, now)
XCTAssertEqual(invoice.date?.date, now)
XCTAssertEqual(invoice.payment?.due, now)
XCTAssertEqual(updated.cc?.last?.email, "dont.ater@example.com")
}
Expand Down Expand Up @@ -212,7 +212,7 @@ final class InvoicesTests: XCTestCase {
}

func testPaymentEndpoint()throws {
let now = Date().isoTZ
let now = Date()
let invoices = try self.app.make(Invoices.self)
guard let id = self.id else {
throw Abort(.internalServerError, reason: "Cannot get ID for updating invoice")
Expand All @@ -225,7 +225,7 @@ final class InvoicesTests: XCTestCase {
}

func testRefundEndpoint()throws {
let now = Date().isoTZ
let now = Date()
let invoices = try self.app.make(Invoices.self)
guard let id = self.id else {
throw Abort(.internalServerError, reason: "Cannot get ID for updating invoice")
Expand Down
4 changes: 2 additions & 2 deletions Tests/ControllerTests/ManagedAccountsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ final class ManagedAccountsTests: XCTestCase {
online: PercentRange(0...1)
),
customerService: CustomerService(
email: EmailAddress(email: .init("help@nameless.com")),
email: .init("help@nameless.com"),
phone: PhoneNumber(country: .init(1), number: .init(9963191901)),
message: []
),
Expand Down Expand Up @@ -166,7 +166,7 @@ final class ManagedAccountsTests: XCTestCase {
online: PercentRange(0...1)
),
customerService: CustomerService(
email: EmailAddress(email: .init("help@nameless.com")),
email: .init("help@nameless.com"),
phone: PhoneNumber(country: .init(1), number: .init(9963191901)),
message: []
),
Expand Down
2 changes: 1 addition & 1 deletion Tests/ControllerTests/PaymentsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ final class PaymentsTests: XCTestCase {
if list.payments?.count ?? 0 > 1 {
let now = Date()
let sorted = list.payments?.sorted { first, second in
return (Date(iso8601: first.created ?? now.iso8601) ?? now > Date(iso8601: second.created ?? now.iso8601) ?? now)
return first.created?.date ?? now > second.created?.date ?? now
}
XCTAssertEqual(sorted, list.payments)
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/ModelTests/AcceptDisputeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ final class AcceptDisputeTests: XCTestCase {
let generated = try String(data: encoder.encode(body), encoding: .utf8)!
let json =
"{\"accept_claim_reason\":\"COMPANY_POLICY\",\"invoice_id\":\"3EC9D031-0DBF-446F-ABC0-31B4A6E0D2B5\"," +
"\"note\":\"Refund to customer\",\"refund_amount\":{\"value\":\"55.50\",\"currency_code\":\"USD\"}}"
"\"note\":\"Refund to customer\",\"refund_amount\":{\"value\":\"55.5\",\"currency_code\":\"USD\"}}"

var index = 0
for (jsonChar, genChar) in zip(json, generated) {
Expand Down
4 changes: 2 additions & 2 deletions Tests/ModelTests/ActivityResponseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ final class ActivityResponseTests: XCTestCase {
let response = Activity.Response(items: [
Activity(
id: "94C67654-A41B-4421-B0D0-81E6CD587CDB",
timeCreated: "2018-07-12T14:14:56Z",
timeCreated: Date(iso8601: "2018-07-12T14:14:56Z")!,
type: .payment,
subtype: nil,
status: .pending,
Expand All @@ -31,7 +31,7 @@ final class ActivityResponseTests: XCTestCase {
XCTAssertEqual(response.items, [
Activity(
id: "94C67654-A41B-4421-B0D0-81E6CD587CDB",
timeCreated: "2018-07-12T14:14:56Z",
timeCreated: Date(iso8601: "2018-07-12T14:14:56Z")!,
type: .payment,
subtype: nil,
status: .pending,
Expand Down
2 changes: 1 addition & 1 deletion Tests/ModelTests/ActivityTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import XCTest
final class ActivityTests: XCTestCase {
let activity = Activity(
id: "94C67654-A41B-4421-B0D0-81E6CD587CDB",
timeCreated: "2018-07-12T14:14:56Z",
timeCreated: Date(iso8601: "2018-07-12T14:14:56Z")!,
type: .payment,
subtype: nil,
status: .pending,
Expand Down
10 changes: 5 additions & 5 deletions Tests/ModelTests/BillingAgreementTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Failable
@testable import PayPal

final class BillingAgreementTests: XCTestCase {
let now = Date().iso8601
let now = Date()

func testInit()throws {
let agreement = try BillingAgreement(
Expand Down Expand Up @@ -100,7 +100,7 @@ final class BillingAgreementTests: XCTestCase {
)
let generated = try String(data: encoder.encode(agreement), encoding: .utf8)!
let json =
"{\"plan\":{\"name\":\"Nia's Maggot Loaf\",\"type\":\"INFINITE\",\"description\":\"Weekly maggot loaf subscription\"},\"start_date\":\"\(now)\"," +
"{\"plan\":{\"name\":\"Nia's Maggot Loaf\",\"type\":\"INFINITE\",\"description\":\"Weekly maggot loaf subscription\"},\"start_date\":\"\(now.iso8601)\"," +
"\"name\":\"Nia's Maggot Loaf\",\"description\":\"Weekly maggot loaf subscription\",\"payer\":{\"payment_method\":\"paypal\"}}"

var index = 0
Expand Down Expand Up @@ -129,7 +129,7 @@ final class BillingAgreementTests: XCTestCase {
{
"name": "Nia's Maggot Loaf",
"description": "Weekly maggot loaf subscription",
"start_date": "\(now)",
"start_date": "\(now.iso8601)",
"payer": {
"payment_method": "paypal"
},
Expand All @@ -144,7 +144,7 @@ final class BillingAgreementTests: XCTestCase {
{
"name": "\(String(repeating: "n", count: 129))",
"description": "Weekly maggot loaf subscription",
"start_date": "\(now)",
"start_date": "\(now.iso8601)",
"payer": {
"payment_method": "paypal"
},
Expand All @@ -159,7 +159,7 @@ final class BillingAgreementTests: XCTestCase {
{
"name": "Nia's Maggot Loaf",
"description": "\(String(repeating: "d", count: 129))",
"start_date": "\(now)",
"start_date": "\(now.iso8601)",
"payer": {
"payment_method": "paypal"
},
Expand Down
18 changes: 2 additions & 16 deletions Tests/ModelTests/BillingPaymentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ final class BillingPaymentTests: XCTestCase {
)
let generated = try String(data: encoder.encode(payment), encoding: .utf8)!
let json =
"{\"cycles\":\"0\",\"amount\":{\"value\":\"24.99\",\"currency_code\":\"USD\"},\"frequency_interval\":\"2\",\"name\":\"Service Membership\"," +
"\"type\":\"REGULAR\",\"frequency\":\"MONTH\"}"
"{\"frequency\":\"MONTH\",\"amount\":{\"value\":\"24.99\",\"currency_code\":\"USD\"},\"frequency_interval\":\"2\",\"cycles\":\"0\"," +
"\"name\":\"Service Membership\",\"type\":\"REGULAR\"}"

var index = 0
for (jsonChar, genChar) in zip(json, generated) {
Expand Down Expand Up @@ -87,23 +87,9 @@ final class BillingPaymentTests: XCTestCase {
"name": "Service Membership"
}
""".data(using: .utf8)!
let intervalError = """
{
"amount": {
"currency_code": "USD",
"value": "24.99"
},
"cycles": "0",
"frequency": "MONTH",
"frequency_interval": "13",
"type": "REGULAR",
"name": "Service Membership"
}
""".data(using: .utf8)!

try XCTAssertEqual(payment, decoder.decode(BillingPayment<CurrencyCodeAmount>.self, from: valid))
try XCTAssertThrowsError(decoder.decode(BillingPayment<CurrencyCodeAmount>.self, from: cyclesError))
try XCTAssertThrowsError(decoder.decode(BillingPayment<CurrencyCodeAmount>.self, from: intervalError))
}

static var allTests: [(String, (BillingPaymentTests) -> ()throws -> ())] = [
Expand Down
4 changes: 2 additions & 2 deletions Tests/ModelTests/BillingPlanListTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ final class BillingPlanListTests: XCTestCase {
])
let generated = try String(data: encoder.encode(list), encoding: .utf8)!
let json =
"{\"plans\":[{\"payment_definitions\":[{\"cycles\":\"0\",\"amount\":{\"value\":\"10.00\",\"currency\":\"USD\"},\"frequency_interval\":\"1\"," +
"\"name\":\"Water Charge\",\"type\":\"REGULAR\",\"frequency\":\"MONTH\"}],\"name\":\"Monthly Water\",\"type\":\"INFINITE\"," +
"{\"plans\":[{\"payment_definitions\":[{\"frequency\":\"MONTH\",\"amount\":{\"currency\":\"USD\",\"value\":\"10\"},\"frequency_interval\":\"1\"," +
"\"cycles\":\"0\",\"name\":\"Water Charge\",\"type\":\"REGULAR\"}],\"name\":\"Monthly Water\",\"type\":\"INFINITE\"," +
"\"description\":\"Your water payment\"}],\"total_items\":\"1\"}"

var index = 0
Expand Down
4 changes: 2 additions & 2 deletions Tests/ModelTests/BillingPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ final class BillingPlanTests: XCTestCase {
)
let generated = try String(data: encoder.encode(plan), encoding: .utf8)!
let json =
"{\"payment_definitions\":[{\"cycles\":\"0\",\"amount\":{\"value\":\"10.00\",\"currency\":\"USD\"},\"frequency_interval\":\"1\"," +
"\"name\":\"Water Charge\",\"type\":\"REGULAR\",\"frequency\":\"MONTH\"}],\"name\":\"Monthly Water\",\"type\":\"INFINITE\"," +
"{\"payment_definitions\":[{\"frequency\":\"MONTH\",\"amount\":{\"currency\":\"USD\",\"value\":\"10\"},\"frequency_interval\":\"1\"," +
"\"cycles\":\"0\",\"name\":\"Water Charge\",\"type\":\"REGULAR\"}],\"name\":\"Monthly Water\",\"type\":\"INFINITE\"," +
"\"description\":\"Your water payment\"}"

var index = 0
Expand Down
14 changes: 8 additions & 6 deletions Tests/ModelTests/BusinessOwnerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import Failable

final class BusinessOwnerTests: XCTestCase {
let (date, dateStr): (Date, String) = {
let date = Date()
return (date, TimelessDate.formatter.string(from: date))
let now = Date()
let str = TimelessDate.formatter.string(from: now)
let date = TimelessDate.formatter.date(from: str)!

return (date, str)
}()

func testInit()throws {
Expand Down Expand Up @@ -70,10 +73,9 @@ final class BusinessOwnerTests: XCTestCase {
)
let generated = try String(data: encoder.encode(owner), encoding: .utf8)!
let json =
"{\"phones\":[],\"account_owner_relationships\":[],\"country_code_of_nationality\":\"GB\",\"date_of_birth\":\"\(dateStr)\"," +
"\"addresses\":[],\"email\":\"business@example.com\",\"occupation\":\"Author\",\"identifications\":[]," +
"\"name\":{\"given_name\":\"Walter\",\"full_name\":\"Sir Walter Scott\",\"prefix\":\"Sir\",\"surname\":\"Scott\"," +
"\"suffix\":\"Bart.\"},\"language_code\":\"en_GB\"}"
"{\"phones\":[],\"country_code_of_nationality\":\"GB\",\"date_of_birth\":\"\(dateStr)\",\"account_owner_relationships\":[]," +
"\"addresses\":[],\"email\":\"business@example.com\",\"identifications\":[],\"occupation\":\"Author\"," +
"\"name\":{},\"language_code\":\"en_GB\"}"

var index = 0
for (jsonChar, genChar) in zip(json, generated) {
Expand Down
15 changes: 6 additions & 9 deletions Tests/ModelTests/BusinessTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class BusinessTests: XCTestCase {
online: PercentRange(0...1)
),
customerService: CustomerService(
email: EmailAddress(email: .init("help@nameless.com")),
email: .init("help@nameless.com"),
phone: PhoneNumber(country: .init(1), number: .init(9963191901)),
message: []
),
Expand Down Expand Up @@ -122,7 +122,7 @@ final class BusinessTests: XCTestCase {
online: nil
),
customerService: CustomerService(
email: EmailAddress(email: .init("help@nameless.com")),
email: .init("help@nameless.com"),
phone: nil,
message: nil
),
Expand All @@ -134,11 +134,10 @@ final class BusinessTests: XCTestCase {

let generated = try String(data: encoder.encode(business), encoding: .utf8)!
let json =
"{\"date_of_registration\":{},\"category\":\"3145\",\"sub_type\":\"UNSELECTED\",\"addresses\":[],\"sub_category\":\"5972\",\"names\":[]," +
"{\"category\":\"3145\",\"sub_type\":\"UNSELECTED\",\"addresses\":[],\"sub_category\":\"5972\",\"names\":[]," +
"\"business_sales_details\":{},\"phones\":[],\"government_body\":{},\"type\":\"INDIVIDUAL\",\"identifications\":[]," +
"\"date_business_established\":{},\"country_code_of_incorporation\":\"US\",\"stakeholders\":[]," +
"\"customer_service\":{\"email\":\"help@nameless.com\"},\"designation\":{},\"merchant_category_code\":\"4653\"," +
"\"place_of_establishment\":{}}"
"\"country_code_of_incorporation\":\"US\",\"stakeholders\":[],\"customer_service\":{\"email\":\"help@nameless.com\"}," +
"\"designation\":{},\"merchant_category_code\":\"4653\",\"place_of_establishment\":{}}"

var index = 0
for (jsonChar, genChar) in zip(json, generated) {
Expand All @@ -164,8 +163,6 @@ final class BusinessTests: XCTestCase {
"category": "3145",
"sub_category": "5972",
"merchant_category_code": "4653",
"date_business_established": {},
"date_of_registration": {},
"dispute_email": null,
"business_sales_details": {},
"customer_service": {
Expand Down Expand Up @@ -201,7 +198,7 @@ final class BusinessTests: XCTestCase {
online: nil
),
customerService: CustomerService(
email: EmailAddress(email: .init("help@nameless.com")),
email: .init("help@nameless.com"),
phone: nil,
message: nil
),
Expand Down
2 changes: 1 addition & 1 deletion Tests/ModelTests/CaptureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class CaptureTests: XCTestCase {
transaction: CurrencyAmount(currency: .usd, value: 1.00)
)
let generated = try String(data: encoder.encode(capture), encoding: .utf8)
let json = "{\"amount\":{\"currency\":\"USD\",\"total\":\"10.00\"},\"transaction_fee\":{\"value\":\"1.00\",\"currency\":\"USD\"}}"
let json = "{\"amount\":{\"total\":\"10\",\"currency\":\"USD\"},\"transaction_fee\":{\"currency\":\"USD\",\"value\":\"1\"}}"

XCTAssertEqual(generated, json)
}
Expand Down
3 changes: 2 additions & 1 deletion Tests/ModelTests/ChargeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ final class ChargeTests: XCTestCase {
}
""".data(using: .utf8)!

try XCTAssertEqual(Charge(type: .tax, amount: CurrencyCodeAmount(currency: .eur, value: 13.54)), decoder.decode(Charge.self, from: json))
let value = Decimal(sign: .plus, exponent: -2, significand: 1354)
try XCTAssertEqual(Charge(type: .tax, amount: CurrencyCodeAmount(currency: .eur, value: value)), decoder.decode(Charge.self, from: json))
}

static var allTests: [(String, (ChargeTests) -> ()throws -> ())] = [
Expand Down
6 changes: 2 additions & 4 deletions Tests/ModelTests/CustomerDisputeListTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ final class CustomerDisputeListTests: XCTestCase {

func testEncoding()throws {
let encoder = JSONEncoder()
let due = Date(timeIntervalSinceNow: 60 * 60 * 24).iso8601
let list = CustomerDisputeList(items: [
CustomerDispute(
transactions: [],
Expand All @@ -66,19 +65,18 @@ final class CustomerDisputeListTests: XCTestCase {
let generated = try String(data: encoder.encode(list), encoding: .utf8)
let json =
"{\"items\":[{\"dispute_amount\":{\"value\":\"89.45\",\"currency_code\":\"USD\"},\"reason\":\"UNAUTHORISED\"," +
"\"seller_response_due_date\":\"\(due)\",\"disputed_transactions\":[]}]}"
"\"seller_response_due_date\":\"\(self.due.iso8601)\",\"disputed_transactions\":[]}]}"

XCTAssertEqual(generated, json)
}

func testDecoding()throws {
let decoder = JSONDecoder()
let due = Date(timeIntervalSinceNow: 60 * 60 * 24).iso8601
let json = """
{
"items": [
{
"seller_response_due_date": "\(due)",
"seller_response_due_date": "\(self.due.iso8601)",
"dispute_amount": {
"value": "89.45",
"currency_code": "USD"
Expand Down
10 changes: 5 additions & 5 deletions Tests/ModelTests/CustomerDisputeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ final class CustomerDisputeTests: XCTestCase {
)
let generated = try String(data: encoder.encode(dispute), encoding: .utf8)!
let json =
"{\"dispute_amount\":{\"value\":\"89.45\",\"currency_code\":\"USD\"},\"reason\":\"UNAUTHORISED\",\"seller_response_due_date\":\"\(self.due)\"," +
"{\"dispute_amount\":{\"value\":\"89.45\",\"currency_code\":\"USD\"},\"reason\":\"UNAUTHORISED\",\"seller_response_due_date\":\"\(self.due.iso8601)\"," +
"\"disputed_transactions\":[]}"

var index = 0
Expand All @@ -82,7 +82,7 @@ final class CustomerDisputeTests: XCTestCase {
let decoder = JSONDecoder()
let min = """
{
"seller_response_due_date": "\(self.due)",
"seller_response_due_date": "\(self.due.iso8601)",
"dispute_amount": {
"value": "89.45",
"currency_code": "USD"
Expand All @@ -94,12 +94,12 @@ final class CustomerDisputeTests: XCTestCase {
let more = """
{
"dispute_id": "B321E1FA-5F62-4599-99C1-C6E933AEBBE4",
"create_time": "\(self.due)",
"update_time": "\(self.due)",
"create_time": "\(self.due.iso8601)",
"update_time": "\(self.due.iso8601)",
"status": "WAITING_FOR_SELLER_RESPONSE",
"dispute_life_cycle_stage": "INQUIRY",
"dispute_channel": "INTERNAL",
"seller_response_due_date": "\(self.due)",
"seller_response_due_date": "\(self.due.iso8601)",
"dispute_amount": {
"value": "89.45",
"currency_code": "USD"
Expand Down
4 changes: 2 additions & 2 deletions Tests/ModelTests/CustomerServiceMessageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ final class CustomerServiceMessageTests: XCTestCase {
)
let json = try String(data: encoder.encode(message), encoding: .utf8)!
let generated =
"{\"seller_message\":\"Titanic sunk...\",\"logo_image_url\":\"url\",\"type\":\"ONLINE\",\"service_image_url\":\"url\",\"headline\":\"Extra!\"}"
"{\"seller_message\":\"Titanic sunk...\",\"logo_image_url\":\"url-placeholder\",\"type\":\"ONLINE\",\"service_image_url\":\"url\",\"headline\":\"Extra!\"}"

var index = 0
for (jsonChar, genChar) in zip(json, generated) {
Expand All @@ -84,7 +84,7 @@ final class CustomerServiceMessageTests: XCTestCase {
{
"type": "ONLINE",
"headline": "Extra!",
"logo_image_url": "url",
"logo_image_url": "url-placeholder",
"service_image_url": "url",
"seller_message": "Titanic sunk..."
}
Expand Down
Loading

0 comments on commit 3583185

Please sign in to comment.