2021-09-29 13:24:47 +00:00
|
|
|
import { getValueWithDefault } from "./utils/Utils";
|
|
|
|
|
|
|
|
export function getGiftCardWithTag(tag, withCode = false) {
|
|
|
|
return getGiftCardsWithTag(1, tag, withCode)
|
2021-09-08 11:32:05 +00:00
|
|
|
.its("body.data.giftCards.edges")
|
|
|
|
.its(0)
|
|
|
|
.its("node");
|
|
|
|
}
|
|
|
|
|
2021-09-29 13:24:47 +00:00
|
|
|
export function getGiftCardsWithTag(first, tag, withCode = false) {
|
|
|
|
const codeLine = getValueWithDefault(withCode, `code`);
|
2021-09-08 11:32:05 +00:00
|
|
|
const query = `query{
|
2022-01-31 08:37:49 +00:00
|
|
|
giftCards(first: ${first}, filter: { code:"", tags: ["${tag}"]}){
|
2021-09-08 11:32:05 +00:00
|
|
|
edges{
|
|
|
|
node{
|
2021-09-29 13:24:47 +00:00
|
|
|
${codeLine}
|
|
|
|
displayCode
|
2021-09-08 11:32:05 +00:00
|
|
|
id
|
|
|
|
isActive
|
|
|
|
expiryDate
|
2021-09-29 13:24:47 +00:00
|
|
|
currentBalance{
|
|
|
|
currency
|
2021-09-08 11:32:05 +00:00
|
|
|
amount
|
|
|
|
}
|
|
|
|
initialBalance{
|
|
|
|
currency
|
|
|
|
amount
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
|
|
|
return cy.sendRequestWithQuery(query);
|
|
|
|
}
|
2021-09-29 13:24:47 +00:00
|
|
|
|
2022-01-31 08:37:49 +00:00
|
|
|
export function getGiftCards(first) {
|
|
|
|
const query = `query{
|
|
|
|
giftCards(first: ${first}){
|
|
|
|
edges{
|
|
|
|
node{
|
|
|
|
displayCode
|
|
|
|
id
|
|
|
|
isActive
|
|
|
|
expiryDate
|
|
|
|
tags{
|
|
|
|
name
|
|
|
|
}
|
|
|
|
currentBalance{
|
|
|
|
currency
|
|
|
|
amount
|
|
|
|
}
|
|
|
|
initialBalance{
|
|
|
|
currency
|
|
|
|
amount
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
|
|
|
return cy.sendRequestWithQuery(query);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getGiftCardsWithCode(code) {
|
|
|
|
const query = `query{
|
|
|
|
giftCards(first:100, filter: { code: "${code}"}){
|
|
|
|
edges{
|
|
|
|
node{
|
|
|
|
code
|
|
|
|
displayCode
|
|
|
|
id
|
|
|
|
isActive
|
|
|
|
expiryDate
|
|
|
|
currentBalance{
|
|
|
|
currency
|
|
|
|
amount
|
|
|
|
}
|
|
|
|
initialBalance{
|
|
|
|
currency
|
|
|
|
amount
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
|
|
|
return cy.sendRequestWithQuery(query).its("body.data.giftCards.edges");
|
|
|
|
}
|
|
|
|
|
2021-09-29 13:24:47 +00:00
|
|
|
export function getGiftCardWithId(id) {
|
|
|
|
const query = `query{
|
|
|
|
giftCard(id:"${id}"){
|
|
|
|
isActive
|
2021-12-17 11:08:13 +00:00
|
|
|
expiryDate
|
2022-01-31 08:37:49 +00:00
|
|
|
tags{
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
2021-09-29 13:24:47 +00:00
|
|
|
currentBalance{
|
|
|
|
currency
|
|
|
|
amount
|
|
|
|
}
|
2022-01-31 08:37:49 +00:00
|
|
|
initialBalance{
|
|
|
|
currency
|
|
|
|
amount
|
|
|
|
}
|
2021-09-29 13:24:47 +00:00
|
|
|
}
|
|
|
|
}`;
|
|
|
|
return cy.sendRequestWithQuery(query).its("body.data.giftCard");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function createGiftCard({ tag, currency, amount }) {
|
|
|
|
const mutation = `mutation{
|
|
|
|
giftCardCreate(input:{
|
2022-01-31 08:37:49 +00:00
|
|
|
addTags:"${tag}"
|
2021-09-29 13:24:47 +00:00
|
|
|
isActive: true
|
|
|
|
balance: {
|
|
|
|
currency: "${currency}"
|
|
|
|
amount: ${amount}
|
|
|
|
}
|
|
|
|
}){
|
|
|
|
errors{
|
|
|
|
field
|
|
|
|
message
|
|
|
|
}
|
|
|
|
giftCard{
|
|
|
|
code
|
|
|
|
id
|
|
|
|
isActive
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
|
|
|
return cy
|
|
|
|
.sendRequestWithQuery(mutation)
|
|
|
|
.its("body.data.giftCardCreate.giftCard");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function giftCardDeactivate(giftCardId) {
|
|
|
|
const mutation = `mutation{
|
|
|
|
giftCardDeactivate(id:"${giftCardId}"){
|
|
|
|
errors{
|
|
|
|
field
|
|
|
|
message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
|
|
|
return cy.sendRequestWithQuery(mutation);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function deleteGiftCard(giftCardId) {
|
|
|
|
const mutation = `mutation{
|
|
|
|
giftCardDelete(id:"${giftCardId}"){
|
|
|
|
errors{
|
|
|
|
field
|
|
|
|
message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
|
|
|
return cy.sendRequestWithQuery(mutation);
|
|
|
|
}
|