SALEOR-7976 add test for create order from checkout as app (#2278)
* add test for create checkout as app * fixes after cr
This commit is contained in:
parent
daba8a381f
commit
f3aa4003fb
2 changed files with 110 additions and 3 deletions
|
@ -10,10 +10,25 @@ 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, updateApp } from "../support/api/requests/Apps";
|
import { createApp, getApp, updateApp } from "../support/api/requests/Apps";
|
||||||
|
import {
|
||||||
|
addShippingMethod,
|
||||||
|
createCheckout,
|
||||||
|
orderCreateFromCheckout,
|
||||||
|
} from "../support/api/requests/Checkout";
|
||||||
import { createVoucher } from "../support/api/requests/Discounts/Vouchers";
|
import { createVoucher } from "../support/api/requests/Discounts/Vouchers";
|
||||||
import { createGiftCard } from "../support/api/requests/GiftCard";
|
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 { getDefaultChannel } from "../support/api/utils/channelsUtils";
|
||||||
|
import { getShippingMethodIdFromCheckout } from "../support/api/utils/ordersUtils";
|
||||||
|
import {
|
||||||
|
createProductInChannel,
|
||||||
|
createTypeAttributeAndCategoryForProduct,
|
||||||
|
deleteProductsStartsWith,
|
||||||
|
} from "../support/api/utils/products/productsUtils";
|
||||||
|
import {
|
||||||
|
createShipping,
|
||||||
|
deleteShippingStartsWith,
|
||||||
|
} from "../support/api/utils/shippingUtils";
|
||||||
import { discountOptions } from "../support/pages/discounts/vouchersPage";
|
import { discountOptions } from "../support/pages/discounts/vouchersPage";
|
||||||
|
|
||||||
describe("As a staff user I want to manage apps", () => {
|
describe("As a staff user I want to manage apps", () => {
|
||||||
|
@ -22,16 +37,54 @@ describe("As a staff user I want to manage apps", () => {
|
||||||
|
|
||||||
let createdApp;
|
let createdApp;
|
||||||
let defaultChannel;
|
let defaultChannel;
|
||||||
|
let address;
|
||||||
|
let warehouse;
|
||||||
|
let shippingMethod;
|
||||||
|
let variantsList;
|
||||||
|
let checkout;
|
||||||
|
const email = `example@example.com`;
|
||||||
|
|
||||||
before(() => {
|
before(() => {
|
||||||
cy.clearSessionData().loginUserViaRequest();
|
cy.clearSessionData().loginUserViaRequest();
|
||||||
deleteAppsStartsWith(startsWith);
|
deleteAppsStartsWith(startsWith);
|
||||||
|
deleteProductsStartsWith(startsWith);
|
||||||
|
deleteShippingStartsWith(startsWith);
|
||||||
|
|
||||||
createApp(name, "MANAGE_APPS").then(app => {
|
createApp(name, "MANAGE_APPS").then(app => {
|
||||||
createdApp = app;
|
createdApp = app;
|
||||||
});
|
});
|
||||||
getDefaultChannel().then(channel => {
|
cy.fixture("addresses")
|
||||||
defaultChannel = channel;
|
.then(addresses => {
|
||||||
});
|
address = addresses.usAddress;
|
||||||
|
getDefaultChannel();
|
||||||
|
})
|
||||||
|
.then(channelResp => {
|
||||||
|
defaultChannel = channelResp;
|
||||||
|
createShipping({
|
||||||
|
channelId: defaultChannel.id,
|
||||||
|
name,
|
||||||
|
address,
|
||||||
|
price: 10,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(
|
||||||
|
({ warehouse: warehouseResp, shippingMethod: shippingMethodResp }) => {
|
||||||
|
warehouse = warehouseResp;
|
||||||
|
shippingMethod = shippingMethodResp;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
createTypeAttributeAndCategoryForProduct({ name })
|
||||||
|
.then(({ productType, attribute, category }) => {
|
||||||
|
createProductInChannel({
|
||||||
|
name,
|
||||||
|
channelId: defaultChannel.id,
|
||||||
|
warehouseId: warehouse.id,
|
||||||
|
productTypeId: productType.id,
|
||||||
|
attributeId: attribute.id,
|
||||||
|
categoryId: category.id,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(({ variantsList: variants }) => (variantsList = variants));
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -157,4 +210,36 @@ describe("As a staff user I want to manage apps", () => {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
it(
|
||||||
|
"should be able to use app to create order from checkout. TC: SALEOR_3005",
|
||||||
|
{ tags: ["@app", "@allEnv", "@stable"] },
|
||||||
|
() => {
|
||||||
|
const token = createdApp.authToken;
|
||||||
|
|
||||||
|
cy.clearSessionData().loginUserViaRequest();
|
||||||
|
updateApp(createdApp.app.id, "HANDLE_CHECKOUTS");
|
||||||
|
|
||||||
|
cy.clearSessionData();
|
||||||
|
|
||||||
|
createCheckout({
|
||||||
|
channelSlug: defaultChannel.slug,
|
||||||
|
email,
|
||||||
|
variantsList,
|
||||||
|
address,
|
||||||
|
billingAddress: address,
|
||||||
|
auth: "token",
|
||||||
|
}).then(({ checkout: checkoutResp }) => {
|
||||||
|
const shippingMethodId = getShippingMethodIdFromCheckout(
|
||||||
|
checkoutResp,
|
||||||
|
shippingMethod.name,
|
||||||
|
);
|
||||||
|
checkout = checkoutResp;
|
||||||
|
addShippingMethod(checkout.id, shippingMethodId);
|
||||||
|
orderCreateFromCheckout(checkout.id, token).then(resp => {
|
||||||
|
expect(resp.id).to.be.not.empty;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -280,3 +280,25 @@ export function getCheckout(token) {
|
||||||
}`;
|
}`;
|
||||||
return cy.sendRequestWithQuery(query).its("body.data.checkout");
|
return cy.sendRequestWithQuery(query).its("body.data.checkout");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function orderCreateFromCheckout(
|
||||||
|
checkoutId,
|
||||||
|
token,
|
||||||
|
removeCheckoutFlag = true,
|
||||||
|
) {
|
||||||
|
const mutation = `mutation {
|
||||||
|
orderCreateFromCheckout(id: "${checkoutId}", removeCheckout: ${removeCheckoutFlag})
|
||||||
|
{
|
||||||
|
order{
|
||||||
|
id
|
||||||
|
}
|
||||||
|
errors{
|
||||||
|
field
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy
|
||||||
|
.sendRequestWithQuery(mutation, token)
|
||||||
|
.its("body.data.orderCreateFromCheckout.order");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue