saleor-dashboard/cypress/support/api/requests/Discounts/Vouchers.js
Ewa Czerniak cea3ead44b
Saleor 7913 fix tests for vouchers (#2242)
* refactor createVoucher tests

* fix for tests in updateVoucher folder

* fix for updateVouchers, createVouchersWithLimits and siteSettings

* remove already declared variable
2022-08-18 15:14:29 +02:00

80 lines
1.6 KiB
JavaScript

import { getValueWithDefault } from "../utils/Utils";
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);
}
export function deleteVouchers(voucherId) {
const mutation = `mutation deleteVouchers{
voucherDelete(id:"${voucherId}"){
errors{
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}
export function createVoucher(
{ name, productId, code = name, type, country },
token,
) {
const discountTypeLines = getValueWithDefault(type, `type:${type}`);
const countryLine = getValueWithDefault(country, `countries:["${country}"]`);
const mutation = `mutation{
voucherCreate(input:{
${discountTypeLines}
${countryLine}
name:"${name}",
code:"${code}"
products:["${productId}"]
}){
voucher{
id
code
}
errors{
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation, token).its("body.data");
}
export function addChannelToVoucher(voucherId, channelId, value) {
const mutation = `mutation{
voucherChannelListingUpdate(id:"${voucherId}" input:{
addChannels:{
channelId:"${channelId}"
discountValue:"${value}"
}
}){
voucher{
id
code
}
errors{
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation).its("body.data");
}