Procuret / procuret-swift

Procuret API Swift library
0 stars 1 forks source link

add passing `Supplier.retrieve` test #8

Closed hwjeremy closed 2 years ago

hwjeremy commented 2 years ago

The objective of this task is to create a passing Supplier.retrieve test case.

You can closely mirror your Human.retrieve work in order to implement this test. The pattern will be very similar. You can get a valid Supplier ID from the Supplier list. Like with Human.retrieve, use the valid Supplier ID to target an Supplier for retrieval.

Then, work your way through the inevitable bugs. If you get stuck, review our notes from the Human.retrieve work. Again, these tasks are very similar, it should be possible to write this test very quickly now that you have learned so much in writing the Human.retrieve test.

Supplier is a large object with a great many types collectively contributing to its form. In particular, the constituent Entity is a huge object. You will likely encounter a great many key errors. Be cool and worth through them methodically. Use the debug data dump to check your keys and value types.

kaythoyet commented 2 years ago

Updates:

Good Lordy do I love the new environment variable.

That said, here's where I'm at. I'm using the supplier ID for Procuret right now from the list, so when I run the test as I have it currently written, the print out in the console looks like this:

Test Suite 'Selected tests' started at 2021-09-28 14:14:26.959
Test Suite 'ProcuretAPITests.xctest' started at 2021-09-28 14:14:26.959
Test Suite 'SupplierTests' started at 2021-09-28 14:14:26.959
Test Case '-[ProcuretAPITests.SupplierTests testRetrieveSupplier]' started.
Making request to Procuret API: /supplier|GET
Raw response data (if any) will be printed below.
--- Begin raw data returned by Procuret API ---
{
    "authorised": false,
    "brand": {
        "created": "2021-05-27 23:49:12.234527",
        "entity_id": 71205185107785336,
        "media": [
            {
                "accent_colour_hex": "64ceb9",
                "logo_url": "https://procuret.com/content/branding/20201104_PR_Procuret_Logo.svg",
                "primary_colour_hex": "64ceb9",
                "scheme": 1
            },
            {
                "accent_colour_hex": "1e1e1e",
                "logo_url": "https://procuret.com/content/branding/20201104_PR_Procuret_Logo.svg",
                "primary_colour_hex": "64ceb9",
                "scheme": 2
            }
        ],
        "name": "Procuret",
        "sale_message": "Thanks for choosing to pay with Procuret."
    },
    "disposition": {
        "count": 1,
        "limit": 20,
        "offset": 0,
        "sequence": 1
    },
    "entity": {
        "business_address": {
            "country": {
                "country_name": "Australia",
                "indexid": 1,
                "iso_3166_a2": "AU",
                "iso_3166_a3": "AUS"
            },
            "created": "2020-02-04 01:13:44.810992",
            "indexid": 10,
            "line_1": "71 York St",
            "line_2": null,
            "line_3": null,
            "line_4": null,
            "locality": "Sydney",
            "postal_code": "2000",
            "region": {
                "abbreviation": "NSW",
                "country_id": 1,
                "indexid": 1,
                "region_name": "New South Wales"
            }
        },
        "created": "2020-02-04 01:13:44.810992",
        "director_count": null,
        "disposition": {
            "count": 1,
            "limit": 1,
            "offset": 0,
            "sequence": 1
        },
        "entity_identifiers": [
            {
                "created": "2020-02-04 01:13:44.825158",
                "identifier": "630036789",
                "identifier_type": {
                    "identifier_name": "Australian Company Number",
                    "identifier_name_short": "ACN",
                    "indexid": 2
                },
                "indexid": 9,
                "modified_by": 102,
                "state_id": 2,
                "state_name": "verified_valid"
            }
        ],
        "entity_type": null,
        "industry_identifiers": [],
        "is_trust": false,
        "legal_entity_name": "PROCURET OPERATING PTY LIMITED",
        "modified": "2020-02-04 01:13:44.810992",
        "phone_number": null,
        "public_id": 71205185107785336,
        "public_id_short": "TWU"
    },
    "indexid": 2,
    "max_transaction_size": [
        {
            "denomination": {
                "exponent": 2,
                "indexid": 1,
                "iso_4217": "AUD",
                "name": "Australian Dollar",
                "symbol": "$"
            },
            "magnitude": "60000"
        },
        {
            "denomination": {
                "exponent": 2,
                "indexid": 2,
                "iso_4217": "NZD",
                "name": "New Zealand Dollar",
                "symbol": "$"
            },
            "magnitude": "65000"
        }
    ],
    "partnership_manager": null
}
--- End raw data returned by Procuret API ---
/Users/kthoyet/Desktop/procuret-swift/Tests/ProcuretAPITests/SupplierTests.swift:28: error: -[ProcuretAPITests.SupplierTests testRetrieveSupplier] : XCTAssertNil failed: "keyNotFound(CodingKeys(stringValue: "id_type", intValue: nil), Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "entity", intValue: nil), CodingKeys(stringValue: "entity_identifiers", intValue: nil), _JSONKey(stringValue: "Index 0", intValue: 0)], debugDescription: "No value associated with key CodingKeys(stringValue: \"id_type\", intValue: nil) (\"id_type\").", underlyingError: nil))" - An error occurred.
/Users/kthoyet/Desktop/procuret-swift/Tests/ProcuretAPITests/SupplierTests.swift:29: error: -[ProcuretAPITests.SupplierTests testRetrieveSupplier] : XCTAssertNotNil failed - Supplier is nil.
Test Case '-[ProcuretAPITests.SupplierTests testRetrieveSupplier]' failed (6.543 seconds).
Test Suite 'SupplierTests' failed at 2021-09-28 14:14:33.502.
     Executed 1 test, with 2 failures (0 unexpected) in 6.543 (6.543) seconds
Test Suite 'ProcuretAPITests.xctest' failed at 2021-09-28 14:14:33.502.
     Executed 1 test, with 2 failures (0 unexpected) in 6.543 (6.543) seconds
Test Suite 'Selected tests' failed at 2021-09-28 14:14:33.502.
     Executed 1 test, with 2 failures (0 unexpected) in 6.543 (6.544) seconds
Program ended with exit code: 1

Now that I've managed to run into this before, I'm just going through the lovely info the API returned to see where the information doesn't quite match up properly.

kaythoyet commented 2 years ago

Error solved, but we are running into the Dictionary issue with this test again as well. Going to go back through the notes from the previous task on this one to verify. I believe you had me delete the variable. Just going to double-check that before I take that action.

hwjeremy commented 2 years ago

@kaythoyet what key is the problem?

kaythoyet commented 2 years ago

@kaythoyet what key is the problem?

"identifier_type" (inside EntityIdentifier).

kaythoyet commented 2 years ago

@kaythoyet what key is the problem?

"identifier_type" (inside EntityIdentifier).

removing it did get rid of the dictionary error (no surprise, as I looked and that was the (temporary) fix you suggested for the Human.retrieve test as well) but it looks like we may run into the same error pattern for the "idString" variable inside of EntityIdentifier.

I'll continue to work my way through and let you know what happens. :)

kaythoyet commented 2 years ago
Test Suite 'Selected tests' started at 2021-09-28 17:06:04.535
Test Suite 'ProcuretAPITests.xctest' started at 2021-09-28 17:06:04.535
Test Suite 'SupplierTests' started at 2021-09-28 17:06:04.535
Test Case '-[ProcuretAPITests.SupplierTests testRetrieveSupplier]' started.
Making request to Procuret API: /supplier|GET
Raw response data (if any) will be printed below.
--- Begin raw data returned by Procuret API ---
{
    "authorised": false,
    "brand": {
        "created": "2021-05-27 23:49:12.234527",
        "entity_id": 71205185107785336,
        "media": [
            {
                "accent_colour_hex": "64ceb9",
                "logo_url": "https://procuret.com/content/branding/20201104_PR_Procuret_Logo.svg",
                "primary_colour_hex": "64ceb9",
                "scheme": 1
            },
            {
                "accent_colour_hex": "1e1e1e",
                "logo_url": "https://procuret.com/content/branding/20201104_PR_Procuret_Logo.svg",
                "primary_colour_hex": "64ceb9",
                "scheme": 2
            }
        ],
        "name": "Procuret",
        "sale_message": "Thanks for choosing to pay with Procuret."
    },
    "disposition": {
        "count": 1,
        "limit": 20,
        "offset": 0,
        "sequence": 1
    },
    "entity": {
        "business_address": {
            "country": {
                "country_name": "Australia",
                "indexid": 1,
                "iso_3166_a2": "AU",
                "iso_3166_a3": "AUS"
            },
            "created": "2020-02-04 01:13:44.810992",
            "indexid": 10,
            "line_1": "71 York St",
            "line_2": null,
            "line_3": null,
            "line_4": null,
            "locality": "Sydney",
            "postal_code": "2000",
            "region": {
                "abbreviation": "NSW",
                "country_id": 1,
                "indexid": 1,
                "region_name": "New South Wales"
            }
        },
        "created": "2020-02-04 01:13:44.810992",
        "director_count": null,
        "disposition": {
            "count": 1,
            "limit": 1,
            "offset": 0,
            "sequence": 1
        },
        "entity_identifiers": [
            {
                "created": "2020-02-04 01:13:44.825158",
                "identifier": "630036789",
                "identifier_type": {
                    "identifier_name": "Australian Company Number",
                    "identifier_name_short": "ACN",
                    "indexid": 2
                },
                "indexid": 9,
                "modified_by": 102,
                "state_id": 2,
                "state_name": "verified_valid"
            }
        ],
        "entity_type": null,
        "industry_identifiers": [],
        "is_trust": false,
        "legal_entity_name": "PROCURET OPERATING PTY LIMITED",
        "modified": "2020-02-04 01:13:44.810992",
        "phone_number": null,
        "public_id": 71205185107785336,
        "public_id_short": "TWU"
    },
    "indexid": 2,
    "max_transaction_size": [
        {
            "denomination": {
                "exponent": 2,
                "indexid": 1,
                "iso_4217": "AUD",
                "name": "Australian Dollar",
                "symbol": "$"
            },
            "magnitude": "60000"
        },
        {
            "denomination": {
                "exponent": 2,
                "indexid": 2,
                "iso_4217": "NZD",
                "name": "New Zealand Dollar",
                "symbol": "$"
            },
            "magnitude": "65000"
        }
    ],
    "partnership_manager": null
}
--- End raw data returned by Procuret API ---
Test Case '-[ProcuretAPITests.SupplierTests testRetrieveSupplier]' passed (0.884 seconds).
Test Suite 'SupplierTests' passed at 2021-09-28 17:06:05.420.
     Executed 1 test, with 0 failures (0 unexpected) in 0.884 (0.884) seconds
Test Suite 'ProcuretAPITests.xctest' passed at 2021-09-28 17:06:05.420.
     Executed 1 test, with 0 failures (0 unexpected) in 0.884 (0.885) seconds
Test Suite 'Selected tests' passed at 2021-09-28 17:06:05.420.
     Executed 1 test, with 0 failures (0 unexpected) in 0.884 (0.885) seconds
Program ended with exit code: 0

Test succeeded.

We did run into a few dictionary issues and some typeMismatch errors though. Adjustments were made accordingly.

kaythoyet commented 2 years ago

We did run into a few dictionary issues and some typeMismatch errors though. Adjustments were made accordingly.

I'm keeping note of these, by the way. I imagine these will need to be addressed at some point down the line, so I figure just in case, I'm keeping tabs. It's nice that we have GitHub to allow us to keep track of issues even when they are closed and pushed, too.

hwjeremy commented 2 years ago

@kaythoyet good stuff Kayla. You've learned much. 22 days to do the first test, then only 1 day to do the second one! Go ahead and close this issue when ready.