Skip to content

Commit 9fda34e

Browse files
authored
Use implicit address fields conversion in Atobarai app (#2153)
* add graphql-config for better ide experience * class for resolving postal code data * test * replace impl * use addres replacement * changelog * fix tests
1 parent 882cee2 commit 9fda34e

19 files changed

+311
-67
lines changed

.changeset/grumpy-laws-care.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"saleor-app-payment-np-atobarai": minor
3+
---
4+
5+
App is now using official Japanese post database to resolve city and neighbourhood from the provided zipcode

apps/np-atobarai/graphql.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { IGraphQLConfig } from "graphql-config";
2+
3+
const config: IGraphQLConfig = {
4+
schema: "graphql/schema.graphql",
5+
};
6+
7+
export default config;

apps/np-atobarai/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"@trpc/server": "catalog:",
5959
"@vercel/otel": "catalog:",
6060
"dynamodb-toolbox": "catalog:",
61+
"jp-zipcode-lookup": "0.3.5",
6162
"modern-errors": "catalog:",
6263
"modern-errors-serialize": "catalog:",
6364
"neverthrow": "catalog:",
@@ -94,9 +95,11 @@
9495
"eslint": "catalog:",
9596
"eslint-plugin-n": "catalog:",
9697
"graphql": "catalog:",
98+
"graphql-config": "5.0.3",
9799
"graphql-tag": "catalog:",
98100
"json-schema-to-typescript": "catalog:",
99101
"next-test-api-route-handler": "catalog:",
102+
"ts-node": "10.9.2",
100103
"tsx": "catalog:",
101104
"typescript": "catalog:",
102105
"vite": "catalog:",

apps/np-atobarai/src/__tests__/mocks/saleor-events/mocked-source-object.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const mockedSourceObject = {
1717
country: {
1818
code: "JP",
1919
},
20-
postalCode: "BillingPostalCode",
20+
postalCode: "1000001",
2121
countryArea: "BillingCountryArea",
2222
streetAddress1: "BillingStreetAddress1",
2323
streetAddress2: "BillingStreetAddress2",
@@ -32,7 +32,7 @@ export const mockedSourceObject = {
3232
country: {
3333
code: "JP",
3434
},
35-
postalCode: "ShippingPostalCode",
35+
postalCode: "1000001",
3636
countryArea: "ShippingCountryArea",
3737
streetAddress1: "ShippingStreetAddress1",
3838
streetAddress2: "ShippingStreetAddress2",

apps/np-atobarai/src/app/api/webhooks/saleor/transaction-refund-requested/use-case.test.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ describe("TransactionRefundRequestedUseCase", () => {
284284
country: {
285285
code: "JP",
286286
},
287-
postalCode: "1234567",
287+
postalCode: "1000001",
288288
countryArea: "Tokyo",
289289
streetAddress1: "1-1-1 Shibuya",
290290
streetAddress2: "Apt 101",
@@ -299,7 +299,7 @@ describe("TransactionRefundRequestedUseCase", () => {
299299
country: {
300300
code: "JP",
301301
},
302-
postalCode: "1234567",
302+
postalCode: "1000001",
303303
countryArea: "Tokyo",
304304
streetAddress1: "1-1-1 Shibuya",
305305
streetAddress2: "Apt 101",
@@ -468,7 +468,7 @@ describe("TransactionRefundRequestedUseCase", () => {
468468
country: {
469469
code: "JP",
470470
},
471-
postalCode: "1234567",
471+
postalCode: "1000001",
472472
countryArea: "Tokyo",
473473
streetAddress1: "1-1-1 Shibuya",
474474
streetAddress2: "Apt 101",
@@ -483,7 +483,7 @@ describe("TransactionRefundRequestedUseCase", () => {
483483
country: {
484484
code: "JP",
485485
},
486-
postalCode: "1234567",
486+
postalCode: "1000001",
487487
countryArea: "Tokyo",
488488
streetAddress1: "1-1-1 Shibuya",
489489
streetAddress2: "Apt 101",
@@ -584,19 +584,19 @@ describe("TransactionRefundRequestedUseCase", () => {
584584
shop_transaction_id: "saleor-transaction-token",
585585
billed_amount: 2500,
586586
customer: {
587-
address: "TokyoTokyoShibuya1-1-1 ShibuyaApt 101",
587+
address: "Tokyo千代田区千代田1-1-1 ShibuyaApt 101",
588588
company_name: "Test Company",
589589
customer_name: "Doe John",
590590
591591
tel: "0123456789",
592-
zip_code: "1234567",
592+
zip_code: "1000001",
593593
},
594594
dest_customer: {
595-
address: "TokyoTokyoShibuya1-1-1 ShibuyaApt 101",
595+
address: "Tokyo千代田区千代田1-1-1 ShibuyaApt 101",
596596
company_name: "Test Company",
597597
customer_name: "Doe John",
598598
tel: "0123456789",
599-
zip_code: "1234567",
599+
zip_code: "1000001",
600600
},
601601
},
602602
],
@@ -657,7 +657,7 @@ describe("TransactionRefundRequestedUseCase", () => {
657657
country: {
658658
code: "JP",
659659
},
660-
postalCode: "1234567",
660+
postalCode: "1000001",
661661
countryArea: "Tokyo",
662662
streetAddress1: "1-1-1 Shibuya",
663663
streetAddress2: "Apt 101",
@@ -672,7 +672,7 @@ describe("TransactionRefundRequestedUseCase", () => {
672672
country: {
673673
code: "JP",
674674
},
675-
postalCode: "1234567",
675+
postalCode: "1000001",
676676
countryArea: "Tokyo",
677677
streetAddress1: "1-1-1 Shibuya",
678678
streetAddress2: "Apt 101",
@@ -746,24 +746,24 @@ describe("TransactionRefundRequestedUseCase", () => {
746746
transactions: [
747747
{
748748
dest_customer: {
749-
address: "TokyoTokyoShibuya1-1-1 ShibuyaApt 101",
749+
address: "Tokyo千代田区千代田1-1-1 ShibuyaApt 101",
750750
company_name: "Test Company",
751751
customer_name: "Doe John",
752752
tel: "0123456789",
753-
zip_code: "1234567",
753+
zip_code: "1000001",
754754
},
755755
billed_amount: 1300,
756756
settlement_type: "02",
757757
shop_order_date: "2023-01-01",
758758
shop_transaction_id: "saleor-transaction-token",
759759
np_transaction_id: mockedAtobaraiTransactionId,
760760
customer: {
761-
address: "TokyoTokyoShibuya1-1-1 ShibuyaApt 101",
761+
address: "Tokyo千代田区千代田1-1-1 ShibuyaApt 101",
762762
company_name: "Test Company",
763763
customer_name: "Doe John",
764764
765765
tel: "0123456789",
766-
zip_code: "1234567",
766+
zip_code: "1000001",
767767
},
768768
goods: [
769769
{
@@ -848,7 +848,7 @@ describe("TransactionRefundRequestedUseCase", () => {
848848
country: {
849849
code: "JP",
850850
},
851-
postalCode: "1234567",
851+
postalCode: "1000001",
852852
countryArea: "Tokyo",
853853
streetAddress1: "1-1-1 Shibuya",
854854
streetAddress2: "Apt 101",
@@ -863,7 +863,7 @@ describe("TransactionRefundRequestedUseCase", () => {
863863
country: {
864864
code: "JP",
865865
},
866-
postalCode: "1234567",
866+
postalCode: "1000001",
867867
countryArea: "Tokyo",
868868
streetAddress1: "1-1-1 Shibuya",
869869
streetAddress2: "Apt 101",
@@ -1104,7 +1104,7 @@ describe("TransactionRefundRequestedUseCase", () => {
11041104
country: {
11051105
code: "JP",
11061106
},
1107-
postalCode: "1234567",
1107+
postalCode: "1000001",
11081108
countryArea: "Tokyo",
11091109
streetAddress1: "1-1-1 Shibuya",
11101110
streetAddress2: "Apt 101",
@@ -1119,7 +1119,7 @@ describe("TransactionRefundRequestedUseCase", () => {
11191119
country: {
11201120
code: "JP",
11211121
},
1122-
postalCode: "1234567",
1122+
postalCode: "1000001",
11231123
countryArea: "Tokyo",
11241124
streetAddress1: "1-1-1 Shibuya",
11251125
streetAddress2: "Apt 101",
@@ -1248,7 +1248,7 @@ describe("TransactionRefundRequestedUseCase", () => {
12481248
country: {
12491249
code: "JP",
12501250
},
1251-
postalCode: "1234567",
1251+
postalCode: "1000001",
12521252
countryArea: "Tokyo",
12531253
streetAddress1: "1-1-1 Shibuya",
12541254
streetAddress2: "Apt 101",
@@ -1263,7 +1263,7 @@ describe("TransactionRefundRequestedUseCase", () => {
12631263
country: {
12641264
code: "JP",
12651265
},
1266-
postalCode: "1234567",
1266+
postalCode: "1000001",
12671267
countryArea: "Tokyo",
12681268
streetAddress1: "1-1-1 Shibuya",
12691269
streetAddress2: "Apt 101",
@@ -1361,7 +1361,7 @@ describe("TransactionRefundRequestedUseCase", () => {
13611361
country: {
13621362
code: "JP",
13631363
},
1364-
postalCode: "1234567",
1364+
postalCode: "1000001",
13651365
countryArea: "Tokyo",
13661366
streetAddress1: "1-1-1 Shibuya",
13671367
streetAddress2: "Apt 101",
@@ -1376,7 +1376,7 @@ describe("TransactionRefundRequestedUseCase", () => {
13761376
country: {
13771377
code: "JP",
13781378
},
1379-
postalCode: "1234567",
1379+
postalCode: "1000001",
13801380
countryArea: "Tokyo",
13811381
streetAddress1: "1-1-1 Shibuya",
13821382
streetAddress2: "Apt 101",
@@ -1521,7 +1521,7 @@ describe("TransactionRefundRequestedUseCase", () => {
15211521
country: {
15221522
code: "JP",
15231523
},
1524-
postalCode: "1234567",
1524+
postalCode: "1000001",
15251525
countryArea: "Tokyo",
15261526
streetAddress1: "1-1-1 Shibuya",
15271527
streetAddress2: "Apt 101",
@@ -1536,7 +1536,7 @@ describe("TransactionRefundRequestedUseCase", () => {
15361536
country: {
15371537
code: "JP",
15381538
},
1539-
postalCode: "1234567",
1539+
postalCode: "1000001",
15401540
countryArea: "Tokyo",
15411541
streetAddress1: "1-1-1 Shibuya",
15421542
streetAddress2: "Apt 101",

apps/np-atobarai/src/modules/atobarai/api/atobarai-change-transaction-payload.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ describe("createAtobaraiChangeTransactionPayload", () => {
3131
{
3232
"billed_amount": 1000,
3333
"customer": {
34-
"address": "BillingCountryAreaTokyoShibuyaBillingStreetAddress1BillingStreetAddress2",
34+
"address": "BillingCountryArea千代田区千代田BillingStreetAddress1BillingStreetAddress2",
3535
"company_name": "BillingCompanyName",
3636
"customer_name": "BillingLastName BillingFirstName",
3737
"email": "[email protected]",
3838
"tel": "0billingPhone",
39-
"zip_code": "BillingPostalCode",
39+
"zip_code": "1000001",
4040
},
4141
"dest_customer": {
42-
"address": "ShippingCountryAreaTokyoShibuyaShippingStreetAddress1ShippingStreetAddress2",
42+
"address": "ShippingCountryArea千代田区千代田ShippingStreetAddress1ShippingStreetAddress2",
4343
"company_name": "ShippingCompanyName",
4444
"customer_name": "ShippingLastName ShippingFirstName",
4545
"tel": "0shippingPhone",
46-
"zip_code": "ShippingPostalCode",
46+
"zip_code": "1000001",
4747
},
4848
"goods": [
4949
{

apps/np-atobarai/src/modules/atobarai/api/atobarai-register-transaction-payload.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ describe("createAtobaraiRegisterTransactionPayload", () => {
2929
{
3030
"billed_amount": 1000,
3131
"customer": {
32-
"address": "BillingCountryAreaTokyoShibuyaBillingStreetAddress1BillingStreetAddress2",
32+
"address": "BillingCountryArea千代田区千代田BillingStreetAddress1BillingStreetAddress2",
3333
"company_name": "BillingCompanyName",
3434
"customer_name": "BillingLastName BillingFirstName",
3535
"email": "[email protected]",
3636
"tel": "0billingPhone",
37-
"zip_code": "BillingPostalCode",
37+
"zip_code": "1000001",
3838
},
3939
"dest_customer": {
40-
"address": "ShippingCountryAreaTokyoShibuyaShippingStreetAddress1ShippingStreetAddress2",
40+
"address": "ShippingCountryArea千代田区千代田ShippingStreetAddress1ShippingStreetAddress2",
4141
"company_name": "ShippingCompanyName",
4242
"customer_name": "ShippingLastName ShippingFirstName",
4343
"tel": "0shippingPhone",
44-
"zip_code": "ShippingPostalCode",
44+
"zip_code": "1000001",
4545
},
4646
"goods": [
4747
{
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { describe, expect, it } from "vitest";
2+
3+
import { AddressFragment } from "@/generated/graphql";
4+
import { AtobaraiAddressFormatter } from "@/modules/atobarai/atobarai-address-formatter";
5+
6+
const addressFragment = {
7+
firstName: "FirstName",
8+
lastName: "LastName",
9+
companyName: "CompanyName",
10+
streetAddress1: "StreetAddress1",
11+
streetAddress2: "StreetAddress2",
12+
phone: "+81PhoneNumber",
13+
postalCode: "1000001",
14+
countryArea: "CountryArea",
15+
country: {
16+
code: "JP",
17+
},
18+
city: "Tokyo",
19+
cityArea: "Shibyua",
20+
} satisfies AddressFragment;
21+
22+
describe("formatAddress", () => {
23+
it("should convert address into Atobarai required address", () => {
24+
const address = new AtobaraiAddressFormatter().formatAddress(addressFragment);
25+
26+
expect(address).toMatchInlineSnapshot(
27+
`"CountryArea千代田区千代田StreetAddress1StreetAddress2"`,
28+
);
29+
});
30+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { AddressFragment } from "@/generated/graphql";
2+
import { JapanesePostalData } from "@/modules/atobarai/japanese-postal-data";
3+
4+
export class AtobaraiAddressFormatter {
5+
/**
6+
* We are using external library that is using japanese post official address data
7+
* to map provided City and Neighbourhood to the one from the external source.
8+
*
9+
* This mimics legacy Saleor plugin behavior.
10+
*/
11+
private postalDataResolver = new JapanesePostalData();
12+
13+
formatAddress = (address: AddressFragment): string => {
14+
const zip = address.postalCode;
15+
const postalDataFrom = this.postalDataResolver.getNeighbourhood(zip);
16+
17+
const localCity = postalDataFrom.city.name;
18+
const localNeighbourhood = postalDataFrom.name;
19+
20+
return `${address.countryArea}${localCity ?? address.city}${
21+
localNeighbourhood ?? address.cityArea
22+
}${address.streetAddress1}${address.streetAddress2}`;
23+
};
24+
}

apps/np-atobarai/src/modules/atobarai/atobarai-address-helpers.test.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { describe, expect, it } from "vitest";
33
import { AddressFragment, SourceObjectFragment } from "@/generated/graphql";
44

55
import {
6-
formatAddress,
76
formatCustomerName,
87
formatPhone,
98
getEmailFromSourceObject,
@@ -89,14 +88,6 @@ describe("formatCustomerName", () => {
8988
});
9089
});
9190

92-
describe("formatAddress", () => {
93-
it("should convert address into Atobarai required address", () => {
94-
const address = formatAddress(addressFragment);
95-
96-
expect(address).toMatchInlineSnapshot(`"CountryAreaTokyoShibyuaStreetAddress1StreetAddress2"`);
97-
});
98-
});
99-
10091
describe("formatPhone", () => {
10192
it("should convert phone number to one that starts with 0 (required by Atobarai)", () => {
10293
const tel = formatPhone(addressFragment.phone);

0 commit comments

Comments
 (0)