2022-02-11 14:58:40 +00:00
|
|
|
import { getValueWithDefault } from "../utils/Utils";
|
|
|
|
|
2021-03-23 10:15:39 +00:00
|
|
|
export function getVouchers(first, startsWith) {
|
|
|
|
const query = `query getVouchers{
|
|
|
|
vouchers(first:${first}, filter:{
|
|
|
|
search:"${startsWith}"
|
|
|
|
}){
|
|
|
|
edges{
|
|
|
|
node{
|
|
|
|
id
|
|
|
|
code
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
|
|
|
return cy
|
|
|
|
.sendRequestWithQuery(query)
|
|
|
|
.then(resp => resp.body.data.vouchers.edges);
|
|
|
|
}
|
2021-10-28 14:43:26 +00:00
|
|
|
|
2021-03-23 10:15:39 +00:00
|
|
|
export function deleteVouchers(voucherId) {
|
|
|
|
const mutation = `mutation deleteVouchers{
|
|
|
|
voucherDelete(id:"${voucherId}"){
|
|
|
|
discountErrors{
|
|
|
|
field
|
|
|
|
message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
|
|
|
return cy.sendRequestWithQuery(mutation);
|
|
|
|
}
|
2021-10-28 14:43:26 +00:00
|
|
|
|
2022-02-11 14:58:40 +00:00
|
|
|
export function createVoucher({ name, productId, code = name, type, country }) {
|
|
|
|
const discountTypeLines = getValueWithDefault(type, `type:${type}`);
|
|
|
|
const countryLine = getValueWithDefault(country, `countries:["${country}"]`);
|
|
|
|
|
2021-10-28 14:43:26 +00:00
|
|
|
const mutation = `mutation{
|
|
|
|
voucherCreate(input:{
|
2022-02-11 14:58:40 +00:00
|
|
|
${discountTypeLines}
|
|
|
|
${countryLine}
|
2021-10-28 14:43:26 +00:00
|
|
|
name:"${name}",
|
|
|
|
code:"${code}"
|
|
|
|
products:["${productId}"]
|
|
|
|
}){
|
|
|
|
voucher{
|
|
|
|
id
|
|
|
|
code
|
|
|
|
}
|
|
|
|
errors{
|
|
|
|
field
|
|
|
|
message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
|
|
|
return cy.sendRequestWithQuery(mutation).its("body.data.voucherCreate");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function addChannelToVoucher(voucherId, channelId, value) {
|
|
|
|
const mutation = `mutation{
|
|
|
|
voucherChannelListingUpdate(id:"${voucherId}" input:{
|
|
|
|
addChannels:{
|
|
|
|
channelId:"${channelId}"
|
|
|
|
discountValue:"${value}"
|
|
|
|
}
|
|
|
|
}){
|
|
|
|
errors{
|
|
|
|
field
|
|
|
|
message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
|
|
|
return cy.sendRequestWithQuery(mutation);
|
|
|
|
}
|