saleor-dashboard/cypress/support/api/requests/Customer.js

151 lines
3.1 KiB
JavaScript
Raw Normal View History

import { getDefaultAddress } from "./utils/Utils";
export function createCustomer(email, customerName, address, isActive = false) {
const mutation = `
mutation{
customerCreate(input:{
firstName: "${customerName}"
lastName: "${customerName}"
email: "${email}"
isActive: ${isActive}
${getDefaultAddress(address, "defaultBillingAddress")}
${getDefaultAddress(address, "defaultShippingAddress")}
}){
user{
id
email
}
accountErrors{
code
message
}
2021-01-27 09:41:55 +00:00
}
}`;
return cy.sendRequestWithQuery(mutation);
}
2021-01-27 09:41:55 +00:00
export function deleteCustomersStartsWith(startsWith) {
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
export function deleteCustomer(customerId) {
const mutation = `mutation{
customerDelete(id:"${customerId}"){
accountErrors{
code
message
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}
2021-01-27 09:41:55 +00:00
export function getCustomers(startsWith) {
const query = `query{
customers(first:100, filter: {
search: "${startsWith}"
}){
edges{
node{
id
email
}
}
}
}`;
return cy.sendRequestWithQuery(query);
2021-01-27 09:41:55 +00:00
}
export function customerRegistration({
email,
password = Cypress.env("USER_PASSWORD"),
channel
}) {
const mutation = `mutation{
accountRegister(input:{
email:"${email}",
password:"${password}"
channel:"${channel}"
redirectUrl: "${Cypress.config().baseUrl}account-confirm"
}){
requiresConfirmation
user{
id
}
errors{
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation).its("body.data.accountRegister");
}
export function requestPasswordReset(email, channel) {
const mutation = `mutation{
requestPasswordReset(channel:"${channel}" email:"${email}", redirectUrl:"${
Cypress.config().baseUrl
}password-reset"){
errors{
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}
export function confirmAccount(email, token) {
const mutation = `mutation{
confirmAccount(email:"${email}", token:"${token}"){
user{
email
}
errors{
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation).its("body.data.confirmAccount");
}
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");
}