-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: set addresses on customer create
Add ability to set shipping and billing addresses when creating customer via the `shippingAddresses` and `billingAddresses`
- Loading branch information
1 parent
fbc8a6f
commit e131b2d
Showing
4 changed files
with
95 additions
and
14 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@labdigital/commercetools-mock": minor | ||
--- | ||
|
||
Add ability to set shipping and billing addresses when creating customer |
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
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,8 @@ | ||
import { Customer, CustomerToken } from "@commercetools/platform-sdk"; | ||
import { | ||
Customer, | ||
CustomerDraft, | ||
CustomerToken, | ||
} from "@commercetools/platform-sdk"; | ||
import assert from "assert"; | ||
import supertest from "supertest"; | ||
import { afterEach, beforeEach, describe, expect, test } from "vitest"; | ||
|
@@ -7,6 +11,46 @@ import { CommercetoolsMock, getBaseResourceProperties } from "../index"; | |
|
||
const ctMock = new CommercetoolsMock(); | ||
|
||
afterEach(() => { | ||
ctMock.clear(); | ||
}); | ||
|
||
describe("Customer create", () => { | ||
test("create new customer", async () => { | ||
const draft: CustomerDraft = { | ||
email: "[email protected]", | ||
password: "supersecret", | ||
authenticationMode: "Password", | ||
stores: [], | ||
addresses: [ | ||
{ | ||
key: "address-key", | ||
firstName: "John", | ||
lastName: "Doe", | ||
streetName: "Main Street", | ||
streetNumber: "1", | ||
postalCode: "12345", | ||
country: "DE", | ||
}, | ||
], | ||
billingAddresses: [0], | ||
shippingAddresses: [0], | ||
}; | ||
|
||
const response = await supertest(ctMock.app) | ||
.post(`/dummy/customers`) | ||
.send(draft); | ||
|
||
const customer = response.body.customer as Customer; | ||
expect(response.status, JSON.stringify(customer)).toBe(201); | ||
expect(customer.version).toBe(1); | ||
expect(customer.defaultBillingAddressId).toBeUndefined(); | ||
expect(customer.defaultShippingAddressId).toBeUndefined(); | ||
expect(customer.billingAddressIds).toHaveLength(1); | ||
expect(customer.shippingAddressIds).toHaveLength(1); | ||
}); | ||
}); | ||
|
||
describe("Customer Update Actions", () => { | ||
let customer: Customer | undefined; | ||
|
||
|
@@ -25,10 +69,6 @@ describe("Customer Update Actions", () => { | |
ctMock.project("dummy").add("customer", customer); | ||
}); | ||
|
||
afterEach(() => { | ||
ctMock.clear(); | ||
}); | ||
|
||
test("exists", async () => { | ||
assert(customer, "customer not created"); | ||
|
||
|
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