2021-03-23 10:15:39 +00:00
|
|
|
import { getDefaultAddress } from "./utils/Utils";
|
2021-03-12 12:14:18 +00:00
|
|
|
export function createCustomer(email, customerName, address, isActive = false) {
|
|
|
|
const mutation = `
|
2021-03-12 14:57:02 +00:00
|
|
|
mutation{
|
|
|
|
customerCreate(input:{
|
|
|
|
firstName: "${customerName}"
|
|
|
|
lastName: "${customerName}"
|
|
|
|
email: "${email}"
|
|
|
|
isActive: ${isActive}
|
2021-03-23 10:15:39 +00:00
|
|
|
${getDefaultAddress(address, "defaultBillingAddress")}
|
|
|
|
${getDefaultAddress(address, "defaultShippingAddress")}
|
2021-03-12 14:57:02 +00:00
|
|
|
}){
|
|
|
|
user{
|
|
|
|
id
|
|
|
|
email
|
|
|
|
}
|
|
|
|
accountErrors{
|
|
|
|
code
|
|
|
|
message
|
|
|
|
}
|
2021-01-27 09:41:55 +00:00
|
|
|
}
|
2021-03-12 14:57:02 +00:00
|
|
|
}`;
|
2021-03-12 12:14:18 +00:00
|
|
|
return cy.sendRequestWithQuery(mutation);
|
|
|
|
}
|
2021-01-27 09:41:55 +00:00
|
|
|
|
2021-03-15 13:16:02 +00:00
|
|
|
export function deleteCustomersStartsWith(startsWith) {
|
2021-03-12 12:14:18 +00:00
|
|
|
getCustomers(startsWith).then(resp => {
|
|
|
|
if (resp.body.data.customers) {
|
|
|
|
const customers = resp.body.data.customers.edges;
|
|
|
|
customers.forEach(element => {
|
|
|
|
if (element.node.email.includes(startsWith)) {
|
|
|
|
deleteCustomer(element.node.id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-01-27 09:41:55 +00:00
|
|
|
|
2021-03-12 12:14:18 +00:00
|
|
|
export function deleteCustomer(customerId) {
|
|
|
|
const mutation = `mutation{
|
2021-03-12 14:57:02 +00:00
|
|
|
customerDelete(id:"${customerId}"){
|
|
|
|
accountErrors{
|
|
|
|
code
|
|
|
|
message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
2021-03-12 12:14:18 +00:00
|
|
|
return cy.sendRequestWithQuery(mutation);
|
|
|
|
}
|
2021-01-27 09:41:55 +00:00
|
|
|
|
2021-03-12 12:14:18 +00:00
|
|
|
export function getCustomers(startsWith) {
|
|
|
|
const query = `query{
|
2021-03-12 14:57:02 +00:00
|
|
|
customers(first:100, filter: {
|
|
|
|
search: "${startsWith}"
|
|
|
|
}){
|
|
|
|
edges{
|
|
|
|
node{
|
|
|
|
id
|
|
|
|
email
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
2021-03-12 12:14:18 +00:00
|
|
|
return cy.sendRequestWithQuery(query);
|
2021-01-27 09:41:55 +00:00
|
|
|
}
|
2021-07-15 10:25:39 +00:00
|
|
|
|
|
|
|
export function getCustomer(customerId) {
|
|
|
|
const query = `query{
|
|
|
|
user(id:"${customerId}"){
|
|
|
|
id
|
|
|
|
email
|
|
|
|
firstName
|
|
|
|
lastName
|
|
|
|
isStaff
|
|
|
|
isActive
|
|
|
|
note
|
|
|
|
addresses{
|
|
|
|
firstName
|
|
|
|
lastName
|
|
|
|
companyName
|
|
|
|
streetAddress1
|
|
|
|
streetAddress2
|
|
|
|
city
|
|
|
|
cityArea
|
|
|
|
postalCode
|
|
|
|
country{
|
|
|
|
code
|
|
|
|
}
|
|
|
|
countryArea
|
|
|
|
phone
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
|
|
|
return cy.sendRequestWithQuery(query).its("body.data.user");
|
|
|
|
}
|