adding tests for app permission, update test for siteSettings, cleanup with variables names (#2183)
This commit is contained in:
parent
62c9f10f64
commit
9d99491623
13 changed files with 191 additions and 131 deletions
|
@ -9,14 +9,19 @@ import { WEBHOOK_DETAILS } from "../elements/apps/webhookDetails";
|
||||||
import { BUTTON_SELECTORS } from "../elements/shared/button-selectors";
|
import { BUTTON_SELECTORS } from "../elements/shared/button-selectors";
|
||||||
import { appDetailsUrl, urlList } from "../fixtures/urlList";
|
import { appDetailsUrl, urlList } from "../fixtures/urlList";
|
||||||
import { ONE_PERMISSION_USERS } from "../fixtures/users";
|
import { ONE_PERMISSION_USERS } from "../fixtures/users";
|
||||||
import { createApp, getApp } from "../support/api/requests/Apps";
|
import { createApp, getApp, updateApp } from "../support/api/requests/Apps";
|
||||||
|
import { createVoucher } from "../support/api/requests/Discounts/Vouchers";
|
||||||
|
import { createGiftCard } from "../support/api/requests/GiftCard";
|
||||||
import { deleteAppsStartsWith } from "../support/api/utils/appUtils";
|
import { deleteAppsStartsWith } from "../support/api/utils/appUtils";
|
||||||
|
import { getDefaultChannel } from "../support/api/utils/channelsUtils";
|
||||||
|
import { discountOptions } from "../support/pages/discounts/vouchersPage";
|
||||||
|
|
||||||
describe("Tests for apps", () => {
|
describe("As a staff user I want to manage apps", () => {
|
||||||
const startsWith = "Apps";
|
const startsWith = "Apps";
|
||||||
const name = `${startsWith}${faker.datatype.number()}`;
|
const name = `${startsWith}${faker.datatype.number()}`;
|
||||||
|
|
||||||
let createdApp;
|
let createdApp;
|
||||||
|
let defaultChannel;
|
||||||
|
|
||||||
before(() => {
|
before(() => {
|
||||||
cy.clearSessionData().loginUserViaRequest();
|
cy.clearSessionData().loginUserViaRequest();
|
||||||
|
@ -24,6 +29,9 @@ describe("Tests for apps", () => {
|
||||||
createApp(name, "MANAGE_APPS").then(app => {
|
createApp(name, "MANAGE_APPS").then(app => {
|
||||||
createdApp = app;
|
createdApp = app;
|
||||||
});
|
});
|
||||||
|
getDefaultChannel().then(channel => {
|
||||||
|
defaultChannel = channel;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -31,16 +39,16 @@ describe("Tests for apps", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it(
|
it(
|
||||||
"should create app. TC: SALEOR_3001",
|
"should be able to create app. TC: SALEOR_3001",
|
||||||
{ tags: ["@app", "@allEnv", "@stable"] },
|
{ tags: ["@app", "@allEnv", "@stable"] },
|
||||||
() => {
|
() => {
|
||||||
const randomName = `${startsWith}${faker.datatype.number()}`;
|
const randomAppName = `${startsWith}${faker.datatype.number()}`;
|
||||||
|
|
||||||
cy.visit(urlList.apps)
|
cy.visit(urlList.apps)
|
||||||
.get(APPS_LIST.createLocalAppButton)
|
.get(APPS_LIST.createLocalAppButton)
|
||||||
.click()
|
.click()
|
||||||
.get(APP_DETAILS.nameInput)
|
.get(APP_DETAILS.nameInput)
|
||||||
.type(randomName)
|
.type(randomAppName)
|
||||||
.get(APP_DETAILS.manageAppsPermissionCheckbox)
|
.get(APP_DETAILS.manageAppsPermissionCheckbox)
|
||||||
.click()
|
.click()
|
||||||
.addAliasToGraphRequest("AppCreate")
|
.addAliasToGraphRequest("AppCreate")
|
||||||
|
@ -53,7 +61,7 @@ describe("Tests for apps", () => {
|
||||||
getApp(app.id);
|
getApp(app.id);
|
||||||
})
|
})
|
||||||
.then(app => {
|
.then(app => {
|
||||||
expect(app.name).to.eq(randomName);
|
expect(app.name).to.eq(randomAppName);
|
||||||
const token = app.tokens.find(element => element.name === "Default");
|
const token = app.tokens.find(element => element.name === "Default");
|
||||||
expect(token).to.be.ok;
|
expect(token).to.be.ok;
|
||||||
});
|
});
|
||||||
|
@ -61,42 +69,42 @@ describe("Tests for apps", () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
it(
|
it(
|
||||||
"should create webhook. TC: SALEOR_3002",
|
"should be able to create webhook. TC: SALEOR_3002",
|
||||||
{ tags: ["@app", "@allEnv", "@stable"] },
|
{ tags: ["@app", "@allEnv", "@stable"] },
|
||||||
() => {
|
() => {
|
||||||
const randomName = `${startsWith}${faker.datatype.number()}`;
|
const randomWebhookName = `${startsWith}${faker.datatype.number()}`;
|
||||||
const targetUrl = `http://example.${randomName}`;
|
const targetUrl = `http://example.${randomWebhookName}`;
|
||||||
|
|
||||||
cy.visit(appDetailsUrl(createdApp.id))
|
cy.visit(appDetailsUrl(createdApp.app.id))
|
||||||
.get(APP_DETAILS.createWebhookButton)
|
.get(APP_DETAILS.createWebhookButton)
|
||||||
.click()
|
.click()
|
||||||
.get(WEBHOOK_DETAILS.nameInput)
|
.get(WEBHOOK_DETAILS.nameInput)
|
||||||
.type(randomName)
|
.type(randomWebhookName)
|
||||||
.get(WEBHOOK_DETAILS.targetUrlInput)
|
.get(WEBHOOK_DETAILS.targetUrlInput)
|
||||||
.type(targetUrl)
|
.type(targetUrl)
|
||||||
.get(BUTTON_SELECTORS.confirm)
|
.get(BUTTON_SELECTORS.confirm)
|
||||||
.click()
|
.click()
|
||||||
.confirmationMessageShouldDisappear();
|
.confirmationMessageShouldDisappear();
|
||||||
getApp(createdApp.id).then(({ webhooks }) => {
|
getApp(createdApp.app.id).then(({ webhooks }) => {
|
||||||
expect(webhooks[0].name).to.eq(randomName);
|
expect(webhooks[0].name).to.eq(randomWebhookName);
|
||||||
expect(webhooks[0].targetUrl).to.eq(targetUrl);
|
expect(webhooks[0].targetUrl).to.eq(targetUrl);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
it(
|
it(
|
||||||
"should create token. TC: SALEOR_3003",
|
"should be able to create token. TC: SALEOR_3003",
|
||||||
{ tags: ["@app", "@allEnv", "@stable"] },
|
{ tags: ["@app", "@allEnv", "@stable"] },
|
||||||
() => {
|
() => {
|
||||||
const randomName = `${startsWith}${faker.datatype.number()}`;
|
const randomTokenName = `${startsWith}${faker.datatype.number()}`;
|
||||||
let expectedToken;
|
let expectedToken;
|
||||||
|
|
||||||
cy.visit(appDetailsUrl(createdApp.id))
|
cy.visit(appDetailsUrl(createdApp.app.id))
|
||||||
.get(APP_DETAILS.createTokenButton)
|
.get(APP_DETAILS.createTokenButton)
|
||||||
.click()
|
.click()
|
||||||
.get(APP_DETAILS.createTokenForm.tokenDialog)
|
.get(APP_DETAILS.createTokenForm.tokenDialog)
|
||||||
.find(APP_DETAILS.createTokenForm.nameInput)
|
.find(APP_DETAILS.createTokenForm.nameInput)
|
||||||
.type(randomName)
|
.type(randomTokenName)
|
||||||
.get(BUTTON_SELECTORS.submit)
|
.get(BUTTON_SELECTORS.submit)
|
||||||
.click()
|
.click()
|
||||||
.get(APP_DETAILS.createTokenForm.tokenToCopy)
|
.get(APP_DETAILS.createTokenForm.tokenToCopy)
|
||||||
|
@ -104,10 +112,12 @@ describe("Tests for apps", () => {
|
||||||
.then(text => {
|
.then(text => {
|
||||||
expectedToken = text;
|
expectedToken = text;
|
||||||
cy.get(APP_DETAILS.createTokenForm.doneButton).click();
|
cy.get(APP_DETAILS.createTokenForm.doneButton).click();
|
||||||
getApp(createdApp.id);
|
getApp(createdApp.app.id);
|
||||||
})
|
})
|
||||||
.then(app => {
|
.then(app => {
|
||||||
const token = app.tokens.find(element => element.name === randomName);
|
const token = app.tokens.find(
|
||||||
|
element => element.name === randomTokenName,
|
||||||
|
);
|
||||||
const tokenLastFourDigits = expectedToken.slice(
|
const tokenLastFourDigits = expectedToken.slice(
|
||||||
expectedToken.length - 4,
|
expectedToken.length - 4,
|
||||||
);
|
);
|
||||||
|
@ -115,4 +125,36 @@ describe("Tests for apps", () => {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
it(
|
||||||
|
"should be able to use app only to manage giftCards. TC: SALEOR_3004",
|
||||||
|
{ tags: ["@app", "@allEnv", "@stable"] },
|
||||||
|
() => {
|
||||||
|
const startsWith = "AppPermission-";
|
||||||
|
const token = createdApp.authToken;
|
||||||
|
const voucherData = {
|
||||||
|
voucherCode: `${startsWith}${faker.datatype.number()}`,
|
||||||
|
voucherValue: 10,
|
||||||
|
discountOption: discountOptions.PERCENTAGE,
|
||||||
|
channelName: defaultChannel.name,
|
||||||
|
};
|
||||||
|
const giftCardData = {
|
||||||
|
tag: `${startsWith}${faker.datatype.number()}`,
|
||||||
|
amount: 150,
|
||||||
|
currency: "USD",
|
||||||
|
};
|
||||||
|
|
||||||
|
cy.clearSessionData().loginUserViaRequest();
|
||||||
|
updateApp(createdApp.app.id, "MANAGE_GIFT_CARD");
|
||||||
|
cy.clearSessionData();
|
||||||
|
|
||||||
|
createVoucher(voucherData, token).then(resp => {
|
||||||
|
expect(resp.voucherCreate).to.be.null;
|
||||||
|
});
|
||||||
|
createGiftCard(giftCardData, token).then(resp => {
|
||||||
|
expect(resp.code).to.be.not.empty;
|
||||||
|
expect(resp.isActive).to.eq(true);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
import faker from "faker";
|
import faker from "faker";
|
||||||
|
|
||||||
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
|
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
|
||||||
import { SITE_SETTINGS_DETAILS } from "../../elements/siteSettings/site-settings-details";
|
|
||||||
import { urlList } from "../../fixtures/urlList";
|
import { urlList } from "../../fixtures/urlList";
|
||||||
import {
|
import {
|
||||||
getShopInfo,
|
getShopInfo,
|
||||||
|
@ -23,47 +22,14 @@ xdescribe("Tests for site settings", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
cy.clearSessionData()
|
|
||||||
.loginUserViaRequest()
|
|
||||||
.visit(urlList.siteSettings);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should change store name", { tags: ["@siteSettings", "@allEnv"] }, () => {
|
|
||||||
const name = `Cypress-${faker.datatype.number()}`;
|
|
||||||
|
|
||||||
cy.get(SITE_SETTINGS_DETAILS.nameInput)
|
|
||||||
.clearAndType(name)
|
|
||||||
.get(BUTTON_SELECTORS.confirm)
|
|
||||||
.click()
|
|
||||||
.confirmationMessageShouldDisappear();
|
|
||||||
getShopInfo().then(shopInfo => {
|
|
||||||
expect(shopInfo.name).to.eq(name);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it(
|
|
||||||
"should change store description",
|
|
||||||
{ tags: ["@siteSettings", "@allEnv"] },
|
|
||||||
() => {
|
|
||||||
const description = faker.lorem.sentence();
|
|
||||||
|
|
||||||
cy.get(SITE_SETTINGS_DETAILS.descriptionInput)
|
|
||||||
.clearAndType(description)
|
|
||||||
.get(BUTTON_SELECTORS.confirm)
|
|
||||||
.click()
|
|
||||||
.confirmationMessageShouldDisappear();
|
|
||||||
getShopInfo().then(shopInfo => {
|
|
||||||
expect(shopInfo.description).to.eq(description);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
it(
|
it(
|
||||||
"should change store address",
|
"should change store address",
|
||||||
{ tags: ["@siteSettings", "@allEnv"] },
|
{ tags: ["@siteSettings", "@allEnv"] },
|
||||||
() => {
|
() => {
|
||||||
cy.fillUpBasicAddress(address)
|
cy.clearSessionData()
|
||||||
|
.loginUserViaRequest()
|
||||||
|
.visit(urlList.siteSettings)
|
||||||
|
.fillUpBasicAddress(address)
|
||||||
.get(BUTTON_SELECTORS.confirm)
|
.get(BUTTON_SELECTORS.confirm)
|
||||||
.click()
|
.click()
|
||||||
.confirmationMessageShouldDisappear();
|
.confirmationMessageShouldDisappear();
|
||||||
|
|
|
@ -59,7 +59,7 @@ describe("As an admin I want to update vouchers", () => {
|
||||||
const name = `${startsWith}${faker.datatype.number()}`;
|
const name = `${startsWith}${faker.datatype.number()}`;
|
||||||
const voucherValue = 50;
|
const voucherValue = 50;
|
||||||
|
|
||||||
let voucher;
|
let voucherCreate;
|
||||||
|
|
||||||
cy.clearSessionData().loginUserViaRequest();
|
cy.clearSessionData().loginUserViaRequest();
|
||||||
createVoucherInChannel({
|
createVoucherInChannel({
|
||||||
|
@ -69,16 +69,16 @@ describe("As an admin I want to update vouchers", () => {
|
||||||
value: voucherValue,
|
value: voucherValue,
|
||||||
})
|
})
|
||||||
.then(voucherResp => {
|
.then(voucherResp => {
|
||||||
voucher = voucherResp;
|
voucherCreate = voucherResp;
|
||||||
expect(voucher.id).to.be.ok;
|
expect(voucherCreate.voucher.id).to.be.ok;
|
||||||
cy.visit(voucherDetailsUrl(voucher.id))
|
cy.visit(voucherDetailsUrl(voucherCreate.voucher.id))
|
||||||
.addAliasToGraphRequest("VoucherDelete")
|
.addAliasToGraphRequest("VoucherDelete")
|
||||||
.get(BUTTON_SELECTORS.deleteButton)
|
.get(BUTTON_SELECTORS.deleteButton)
|
||||||
.click()
|
.click()
|
||||||
.get(BUTTON_SELECTORS.submit)
|
.get(BUTTON_SELECTORS.submit)
|
||||||
.click()
|
.click()
|
||||||
.wait("@VoucherDelete");
|
.wait("@VoucherDelete");
|
||||||
dataForCheckout.voucherCode = voucher.code;
|
dataForCheckout.voucherCode = voucherCreate.code;
|
||||||
window.sessionStorage.setItem("token", "");
|
window.sessionStorage.setItem("token", "");
|
||||||
dataForCheckout.auth = "token";
|
dataForCheckout.auth = "token";
|
||||||
createCheckoutWithVoucher(dataForCheckout);
|
createCheckoutWithVoucher(dataForCheckout);
|
||||||
|
@ -102,7 +102,7 @@ describe("As an admin I want to update vouchers", () => {
|
||||||
shippingPrice -
|
shippingPrice -
|
||||||
(productPrice * voucherUpdatedValue) / 100;
|
(productPrice * voucherUpdatedValue) / 100;
|
||||||
|
|
||||||
let voucher;
|
let voucherCreate;
|
||||||
|
|
||||||
cy.clearSessionData().loginUserViaRequest();
|
cy.clearSessionData().loginUserViaRequest();
|
||||||
createVoucherInChannel({
|
createVoucherInChannel({
|
||||||
|
@ -112,9 +112,9 @@ describe("As an admin I want to update vouchers", () => {
|
||||||
value: voucherValue,
|
value: voucherValue,
|
||||||
})
|
})
|
||||||
.then(voucherResp => {
|
.then(voucherResp => {
|
||||||
voucher = voucherResp;
|
voucherCreate = voucherResp;
|
||||||
expect(voucher.id).to.be.ok;
|
expect(voucherCreate.voucher.id).to.be.ok;
|
||||||
cy.visit(voucherDetailsUrl(voucher.id))
|
cy.visit(voucherDetailsUrl(voucherCreate.voucher.id))
|
||||||
.addAliasToGraphRequest("VoucherUpdate")
|
.addAliasToGraphRequest("VoucherUpdate")
|
||||||
.get(VOUCHERS_SELECTORS.percentageDiscountRadioButton)
|
.get(VOUCHERS_SELECTORS.percentageDiscountRadioButton)
|
||||||
.click()
|
.click()
|
||||||
|
@ -123,7 +123,7 @@ describe("As an admin I want to update vouchers", () => {
|
||||||
.get(BUTTON_SELECTORS.confirm)
|
.get(BUTTON_SELECTORS.confirm)
|
||||||
.click()
|
.click()
|
||||||
.wait("@VoucherUpdate");
|
.wait("@VoucherUpdate");
|
||||||
dataForCheckout.voucherCode = voucher.code;
|
dataForCheckout.voucherCode = voucherCreate.voucher.code;
|
||||||
window.sessionStorage.setItem("token", "");
|
window.sessionStorage.setItem("token", "");
|
||||||
dataForCheckout.auth = "token";
|
dataForCheckout.auth = "token";
|
||||||
createCheckoutWithVoucher(dataForCheckout);
|
createCheckoutWithVoucher(dataForCheckout);
|
||||||
|
@ -146,7 +146,7 @@ describe("As an admin I want to update vouchers", () => {
|
||||||
const todayDate = formatDate(today);
|
const todayDate = formatDate(today);
|
||||||
const tomorrowDate = formatDate(tomorrow.setDate(tomorrow.getDate() + 1));
|
const tomorrowDate = formatDate(tomorrow.setDate(tomorrow.getDate() + 1));
|
||||||
|
|
||||||
let voucher;
|
let voucherCreate;
|
||||||
|
|
||||||
cy.clearSessionData().loginUserViaRequest();
|
cy.clearSessionData().loginUserViaRequest();
|
||||||
createVoucherInChannel({
|
createVoucherInChannel({
|
||||||
|
@ -156,17 +156,23 @@ describe("As an admin I want to update vouchers", () => {
|
||||||
value: voucherValue,
|
value: voucherValue,
|
||||||
})
|
})
|
||||||
.then(voucherResp => {
|
.then(voucherResp => {
|
||||||
voucher = voucherResp;
|
voucherCreate = voucherResp;
|
||||||
expect(voucher.id).to.be.ok;
|
expect(voucherCreate.voucher.id).to.be.ok;
|
||||||
setVoucherDate({ voucherId: voucher.id, startDate: tomorrowDate });
|
setVoucherDate({
|
||||||
dataForCheckout.voucherCode = voucher.code;
|
voucherId: voucherCreate.voucher.id,
|
||||||
|
startDate: tomorrowDate,
|
||||||
|
});
|
||||||
|
dataForCheckout.voucherCode = voucherCreate.voucher.code;
|
||||||
createCheckoutWithVoucher(dataForCheckout);
|
createCheckoutWithVoucher(dataForCheckout);
|
||||||
})
|
})
|
||||||
.then(({ addPromoCodeResp }) => {
|
.then(({ addPromoCodeResp }) => {
|
||||||
const errorField = addPromoCodeResp.errors[0].field;
|
const errorField = addPromoCodeResp.errors[0].field;
|
||||||
expect(errorField).to.be.eq("promoCode");
|
expect(errorField).to.be.eq("promoCode");
|
||||||
setVoucherDate({ voucherId: voucher.id, startDate: todayDate });
|
setVoucherDate({
|
||||||
dataForCheckout.voucherCode = voucher.code;
|
voucherId: voucherCreate.voucher.id,
|
||||||
|
startDate: todayDate,
|
||||||
|
});
|
||||||
|
dataForCheckout.voucherCode = voucherCreate.voucher.code;
|
||||||
window.sessionStorage.setItem("token", "");
|
window.sessionStorage.setItem("token", "");
|
||||||
dataForCheckout.auth = "token";
|
dataForCheckout.auth = "token";
|
||||||
createCheckoutWithVoucher(dataForCheckout);
|
createCheckoutWithVoucher(dataForCheckout);
|
||||||
|
@ -188,7 +194,7 @@ describe("As an admin I want to update vouchers", () => {
|
||||||
const tomorrow = new Date(today);
|
const tomorrow = new Date(today);
|
||||||
const tomorrowDate = formatDate(tomorrow.setDate(tomorrow.getDate() + 1));
|
const tomorrowDate = formatDate(tomorrow.setDate(tomorrow.getDate() + 1));
|
||||||
|
|
||||||
let voucher;
|
let voucherCreate;
|
||||||
|
|
||||||
cy.clearSessionData().loginUserViaRequest();
|
cy.clearSessionData().loginUserViaRequest();
|
||||||
createVoucherInChannel({
|
createVoucherInChannel({
|
||||||
|
@ -198,15 +204,15 @@ describe("As an admin I want to update vouchers", () => {
|
||||||
value: voucherValue,
|
value: voucherValue,
|
||||||
})
|
})
|
||||||
.then(voucherResp => {
|
.then(voucherResp => {
|
||||||
voucher = voucherResp;
|
voucherCreate = voucherResp;
|
||||||
expect(voucher.id).to.be.ok;
|
expect(voucherCreate.voucher.id).to.be.ok;
|
||||||
setVoucherDate({
|
setVoucherDate({
|
||||||
voucherId: voucher.id,
|
voucherId: voucherCreate.voucher.id,
|
||||||
endDate: todayDate,
|
endDate: todayDate,
|
||||||
endTime: formatTime(today),
|
endTime: formatTime(today),
|
||||||
hasEndDate: true,
|
hasEndDate: true,
|
||||||
});
|
});
|
||||||
dataForCheckout.voucherCode = voucher.code;
|
dataForCheckout.voucherCode = voucherCreate.voucher.code;
|
||||||
window.sessionStorage.setItem("token", "");
|
window.sessionStorage.setItem("token", "");
|
||||||
dataForCheckout.auth = "token";
|
dataForCheckout.auth = "token";
|
||||||
createCheckoutWithVoucher(dataForCheckout);
|
createCheckoutWithVoucher(dataForCheckout);
|
||||||
|
@ -215,11 +221,11 @@ describe("As an admin I want to update vouchers", () => {
|
||||||
const errorField = addPromoCodeResp.errors[0].field;
|
const errorField = addPromoCodeResp.errors[0].field;
|
||||||
expect(errorField).to.be.eq("promoCode");
|
expect(errorField).to.be.eq("promoCode");
|
||||||
setVoucherDate({
|
setVoucherDate({
|
||||||
voucherId: voucher.id,
|
voucherId: voucherCreate.voucher.id,
|
||||||
endDate: tomorrowDate,
|
endDate: tomorrowDate,
|
||||||
endTime: formatTime(tomorrow),
|
endTime: formatTime(tomorrow),
|
||||||
});
|
});
|
||||||
dataForCheckout.voucherCode = voucher.code;
|
dataForCheckout.voucherCode = voucherCreate.voucher.code;
|
||||||
createCheckoutWithVoucher(dataForCheckout);
|
createCheckoutWithVoucher(dataForCheckout);
|
||||||
})
|
})
|
||||||
.then(({ addPromoCodeResp }) => {
|
.then(({ addPromoCodeResp }) => {
|
||||||
|
@ -235,7 +241,7 @@ describe("As an admin I want to update vouchers", () => {
|
||||||
const name = `${startsWith}${faker.datatype.number()}`;
|
const name = `${startsWith}${faker.datatype.number()}`;
|
||||||
const voucherValue = 50;
|
const voucherValue = 50;
|
||||||
|
|
||||||
let voucher;
|
let voucherCreate;
|
||||||
|
|
||||||
cy.clearSessionData().loginUserViaRequest();
|
cy.clearSessionData().loginUserViaRequest();
|
||||||
createVoucherInChannel({
|
createVoucherInChannel({
|
||||||
|
@ -247,16 +253,16 @@ describe("As an admin I want to update vouchers", () => {
|
||||||
country: "US",
|
country: "US",
|
||||||
})
|
})
|
||||||
.then(voucherResp => {
|
.then(voucherResp => {
|
||||||
voucher = voucherResp;
|
voucherCreate = voucherResp;
|
||||||
expect(voucher.id).to.be.ok;
|
expect(voucherCreate.voucher.id).to.be.ok;
|
||||||
dataForCheckout.voucherCode = voucher.code;
|
dataForCheckout.voucherCode = voucherCreate.voucher.code;
|
||||||
window.sessionStorage.setItem("token", "");
|
window.sessionStorage.setItem("token", "");
|
||||||
dataForCheckout.auth = "token";
|
dataForCheckout.auth = "token";
|
||||||
createCheckoutWithVoucher(dataForCheckout);
|
createCheckoutWithVoucher(dataForCheckout);
|
||||||
})
|
})
|
||||||
.then(({ addPromoCodeResp }) => {
|
.then(({ addPromoCodeResp }) => {
|
||||||
expect(addPromoCodeResp.errors).to.be.empty;
|
expect(addPromoCodeResp.errors).to.be.empty;
|
||||||
cy.visit(voucherDetailsUrl(voucher.id))
|
cy.visit(voucherDetailsUrl(voucherCreate.voucher.id))
|
||||||
.get(VOUCHERS_SELECTORS.shippingDiscountRadioButton)
|
.get(VOUCHERS_SELECTORS.shippingDiscountRadioButton)
|
||||||
.click()
|
.click()
|
||||||
.get(VOUCHERS_SELECTORS.countriesDropdownIcon)
|
.get(VOUCHERS_SELECTORS.countriesDropdownIcon)
|
||||||
|
|
|
@ -7,6 +7,6 @@ export const APP_DETAILS = {
|
||||||
tokenDialog: '[role="dialog"]',
|
tokenDialog: '[role="dialog"]',
|
||||||
nameInput: '[name="name"]',
|
nameInput: '[name="name"]',
|
||||||
tokenToCopy: '[data-test-id="generated-token"]',
|
tokenToCopy: '[data-test-id="generated-token"]',
|
||||||
doneButton: '[data-test-id="done"]'
|
doneButton: '[data-test-id="done"]',
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
export const SITE_SETTINGS_DETAILS = {
|
export const SITE_SETTINGS_DETAILS = {
|
||||||
nameInput: '[name="name"]',
|
|
||||||
descriptionInput: '[name="description"]',
|
|
||||||
stockReservationAuthenticatedUserInput:
|
stockReservationAuthenticatedUserInput:
|
||||||
'[name="reserveStockDurationAuthenticatedUser"]',
|
'[name="reserveStockDurationAuthenticatedUser"]',
|
||||||
stockReservationAnonymousUserInput:
|
stockReservationAnonymousUserInput:
|
||||||
'[name="reserveStockDurationAnonymousUser"]'
|
'[name="reserveStockDurationAnonymousUser"]',
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,7 +11,7 @@ export function createApp(name, permission) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
return cy.sendRequestWithQuery(mutation).its("body.data.appCreate.app");
|
return cy.sendRequestWithQuery(mutation).its("body.data.appCreate");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getApps(first, search) {
|
export function getApps(first, search) {
|
||||||
|
@ -61,3 +61,19 @@ export function getApp(appId) {
|
||||||
}`;
|
}`;
|
||||||
return cy.sendRequestWithQuery(query).its("body.data.app");
|
return cy.sendRequestWithQuery(query).its("body.data.app");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function updateApp(appId, permission) {
|
||||||
|
const mutation = `mutation{
|
||||||
|
appUpdate(id:"${appId}" input:{permissions: [${permission}]}){
|
||||||
|
errors{
|
||||||
|
code
|
||||||
|
}
|
||||||
|
app{
|
||||||
|
permissions{
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(mutation);
|
||||||
|
}
|
||||||
|
|
|
@ -30,7 +30,10 @@ export function deleteVouchers(voucherId) {
|
||||||
return cy.sendRequestWithQuery(mutation);
|
return cy.sendRequestWithQuery(mutation);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createVoucher({ name, productId, code = name, type, country }) {
|
export function createVoucher(
|
||||||
|
{ name, productId, code = name, type, country },
|
||||||
|
token,
|
||||||
|
) {
|
||||||
const discountTypeLines = getValueWithDefault(type, `type:${type}`);
|
const discountTypeLines = getValueWithDefault(type, `type:${type}`);
|
||||||
const countryLine = getValueWithDefault(country, `countries:["${country}"]`);
|
const countryLine = getValueWithDefault(country, `countries:["${country}"]`);
|
||||||
|
|
||||||
|
@ -52,7 +55,7 @@ export function createVoucher({ name, productId, code = name, type, country }) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
return cy.sendRequestWithQuery(mutation).its("body.data.voucherCreate");
|
return cy.sendRequestWithQuery(mutation, token).its("body.data");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addChannelToVoucher(voucherId, channelId, value) {
|
export function addChannelToVoucher(voucherId, channelId, value) {
|
||||||
|
|
|
@ -107,7 +107,10 @@ export function getGiftCardWithId(id) {
|
||||||
return cy.sendRequestWithQuery(query).its("body.data.giftCard");
|
return cy.sendRequestWithQuery(query).its("body.data.giftCard");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createGiftCard({ tag, currency, amount, isActive = true }) {
|
export function createGiftCard(
|
||||||
|
{ tag, currency, amount, isActive = true },
|
||||||
|
token,
|
||||||
|
) {
|
||||||
const mutation = `mutation{
|
const mutation = `mutation{
|
||||||
giftCardCreate(input:{
|
giftCardCreate(input:{
|
||||||
addTags:"${tag}"
|
addTags:"${tag}"
|
||||||
|
@ -129,7 +132,7 @@ export function createGiftCard({ tag, currency, amount, isActive = true }) {
|
||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
return cy
|
return cy
|
||||||
.sendRequestWithQuery(mutation)
|
.sendRequestWithQuery(mutation, token)
|
||||||
.its("body.data.giftCardCreate.giftCard");
|
.its("body.data.giftCardCreate.giftCard");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
46
cypress/support/api/requests/utils/index.js
Normal file
46
cypress/support/api/requests/utils/index.js
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
// / <reference types="cypress" />
|
||||||
|
|
||||||
|
import { urlList } from "../../../../fixtures/urlList";
|
||||||
|
|
||||||
|
Cypress.Commands.add(
|
||||||
|
"sendRequestWithQuery",
|
||||||
|
(query, authorization = "auth", variables = "") => {
|
||||||
|
if (authorization.length !== 30) {
|
||||||
|
cy.request({
|
||||||
|
body: {
|
||||||
|
variables,
|
||||||
|
query,
|
||||||
|
},
|
||||||
|
headers: {
|
||||||
|
Authorization: `JWT ${window.sessionStorage.getItem(authorization)}`,
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
url: urlList.apiUri,
|
||||||
|
log: true,
|
||||||
|
}).then(response => {
|
||||||
|
const respInSting = JSON.stringify(response.body);
|
||||||
|
if (respInSting.includes(`"errors":[{`)) {
|
||||||
|
cy.log(query).log(JSON.stringify(response.body));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
cy.request({
|
||||||
|
body: {
|
||||||
|
variables,
|
||||||
|
query,
|
||||||
|
},
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${authorization}`,
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
url: urlList.apiUri,
|
||||||
|
log: true,
|
||||||
|
}).then(response => {
|
||||||
|
const respInSting = JSON.stringify(response.body);
|
||||||
|
if (respInSting.includes(`"errors":[{`)) {
|
||||||
|
cy.log(query).log(JSON.stringify(response.body));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
|
@ -2,7 +2,7 @@ import {
|
||||||
addChannelToVoucher,
|
addChannelToVoucher,
|
||||||
createVoucher,
|
createVoucher,
|
||||||
deleteVouchers,
|
deleteVouchers,
|
||||||
getVouchers
|
getVouchers,
|
||||||
} from "../../requests/Discounts/Vouchers";
|
} from "../../requests/Discounts/Vouchers";
|
||||||
|
|
||||||
export function deleteVouchersStartsWith(startsWith) {
|
export function deleteVouchersStartsWith(startsWith) {
|
||||||
|
@ -16,13 +16,14 @@ export function createVoucherInChannel({
|
||||||
value,
|
value,
|
||||||
code = name,
|
code = name,
|
||||||
type,
|
type,
|
||||||
country
|
country,
|
||||||
}) {
|
}) {
|
||||||
let voucher;
|
let voucherCreate;
|
||||||
|
|
||||||
return createVoucher({ name, productId, code, type, country })
|
return createVoucher({ name, productId, code, type, country })
|
||||||
.then(({ voucher: voucherResp }) => {
|
.then(({ voucherCreate: voucherResp }) => {
|
||||||
voucher = voucherResp;
|
voucherCreate = voucherResp;
|
||||||
addChannelToVoucher(voucher.id, channelId, value);
|
addChannelToVoucher(voucherCreate.voucher.id, channelId, value);
|
||||||
})
|
})
|
||||||
.then(() => voucher);
|
.then(() => voucherCreate);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import "../../api/requests/utils/index";
|
||||||
|
|
||||||
import { LOGIN_SELECTORS } from "../../../elements/account/login-selectors";
|
import { LOGIN_SELECTORS } from "../../../elements/account/login-selectors";
|
||||||
import { TEST_ADMIN_USER } from "../../../fixtures/users";
|
import { TEST_ADMIN_USER } from "../../../fixtures/users";
|
||||||
|
|
||||||
|
@ -8,7 +10,7 @@ Cypress.Commands.add("loginUser", () =>
|
||||||
.get(LOGIN_SELECTORS.emailPasswordInput)
|
.get(LOGIN_SELECTORS.emailPasswordInput)
|
||||||
.type(Cypress.env("USER_PASSWORD"), { log: false })
|
.type(Cypress.env("USER_PASSWORD"), { log: false })
|
||||||
.get(LOGIN_SELECTORS.signInButton)
|
.get(LOGIN_SELECTORS.signInButton)
|
||||||
.click()
|
.click(),
|
||||||
);
|
);
|
||||||
|
|
||||||
Cypress.Commands.add("loginInShop", () => {
|
Cypress.Commands.add("loginInShop", () => {
|
||||||
|
@ -36,12 +38,12 @@ Cypress.Commands.add(
|
||||||
return cy.sendRequestWithQuery(mutation, authorization).then(resp => {
|
return cy.sendRequestWithQuery(mutation, authorization).then(resp => {
|
||||||
window.localStorage.setItem(
|
window.localStorage.setItem(
|
||||||
"_saleorCSRFToken",
|
"_saleorCSRFToken",
|
||||||
resp.body.data.tokenCreate.csrfToken
|
resp.body.data.tokenCreate.csrfToken,
|
||||||
);
|
);
|
||||||
window.sessionStorage.setItem(
|
window.sessionStorage.setItem(
|
||||||
authorization,
|
authorization,
|
||||||
resp.body.data.tokenCreate.token
|
resp.body.data.tokenCreate.token,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -47,29 +47,6 @@ Cypress.Commands.add("addAliasToGraphRequest", operationName => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
Cypress.Commands.add(
|
|
||||||
"sendRequestWithQuery",
|
|
||||||
(query, authorization = "auth", variables = "") =>
|
|
||||||
cy
|
|
||||||
.request({
|
|
||||||
body: {
|
|
||||||
variables,
|
|
||||||
query,
|
|
||||||
},
|
|
||||||
headers: {
|
|
||||||
Authorization: `JWT ${window.sessionStorage.getItem(authorization)}`,
|
|
||||||
},
|
|
||||||
method: "POST",
|
|
||||||
url: urlList.apiUri,
|
|
||||||
log: true,
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
const respInSting = JSON.stringify(response.body);
|
|
||||||
if (respInSting.includes(`"errors":[{`)) {
|
|
||||||
cy.log(query).log(JSON.stringify(response.body));
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
Cypress.on(
|
Cypress.on(
|
||||||
"uncaught:exception",
|
"uncaught:exception",
|
||||||
(err, runnable) =>
|
(err, runnable) =>
|
||||||
|
|
|
@ -17,5 +17,5 @@ export function enterSiteSettingAndSetStockReservation(userType, stockAmount) {
|
||||||
|
|
||||||
export const userType = {
|
export const userType = {
|
||||||
anonymous: SITE_SETTINGS_DETAILS.stockReservationAnonymousUserInput,
|
anonymous: SITE_SETTINGS_DETAILS.stockReservationAnonymousUserInput,
|
||||||
authenticated: SITE_SETTINGS_DETAILS.stockReservationAuthenticatedUserInput
|
authenticated: SITE_SETTINGS_DETAILS.stockReservationAuthenticatedUserInput,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue