feat: customer-information (#413)

* added the ability to update email as long as user has_account=false

* revamped and added fix for MC-132

Co-authored-by: olivermrbl <oliver@mrbltech.com>
This commit is contained in:
Sebastian Mateos Nicolajsen
2021-09-23 10:22:18 +02:00
committed by GitHub
parent 897ccf475a
commit a70e3ed0ae
7 changed files with 91 additions and 15 deletions

View File

@@ -57,7 +57,7 @@ describe("/admin/customers", () => {
})
expect(response.status).toEqual(200)
expect(response.data.count).toEqual(3)
expect(response.data.count).toEqual(4)
expect(response.data.customers).toEqual(
expect.arrayContaining([
expect.objectContaining({
@@ -69,6 +69,9 @@ describe("/admin/customers", () => {
expect.objectContaining({
id: "test-customer-3",
}),
expect.objectContaining({
id: "test-customer-has_account",
}),
])
)
})
@@ -129,4 +132,51 @@ describe("/admin/customers", () => {
)
})
})
describe("POST /admin/customers/:id", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("Correctly updates customer", async () => {
const api = useApi()
const response = await api
.post(
"/admin/customers/test-customer-3",
{
first_name: "newf",
last_name: "newl",
email: "new@email.com",
},
{
headers: {
Authorization: "Bearer test_token",
},
}
)
.catch((err) => {
console.log(err)
})
expect(response.status).toEqual(200)
expect(response.data.customer).toEqual(
expect.objectContaining({
first_name: "newf",
last_name: "newl",
email: "new@email.com",
})
)
})
})
})

View File

@@ -1,27 +1,33 @@
const { Customer, Address } = require("@medusajs/medusa");
const { Customer, Address } = require("@medusajs/medusa")
module.exports = async (connection, data = {}) => {
const manager = connection.manager;
const manager = connection.manager
await manager.insert(Customer, {
id: "test-customer-1",
email: "test1@email.com",
});
})
await manager.insert(Customer, {
id: "test-customer-2",
email: "test2@email.com",
});
})
await manager.insert(Customer, {
id: "test-customer-3",
email: "test3@email.com",
});
})
await manager.insert(Customer, {
id: "test-customer-has_account",
email: "test4@email.com",
has_account: true,
})
await manager.insert(Address, {
id: "test-address",
first_name: "Lebron",
last_name: "James",
customer_id: "test-customer-1",
});
};
})
}