order ready to fulfill created

This commit is contained in:
Karolina Rakoczy 2021-01-27 10:41:55 +01:00
parent f9e8090120
commit 95be7b5163
8 changed files with 414 additions and 98 deletions

84
cypress/api/Customer.js Normal file
View file

@ -0,0 +1,84 @@
export class Customer {
createCustomer(email, customerName, address, isActive = false) {
const mutation = `
mutation{
customerCreate(input:{
firstName: "${customerName}"
lastName: "${customerName}"
email: "${email}"
isActive: ${isActive}
defaultBillingAddress: {
companyName: "${address.companyName}"
streetAddress1: "${address.streetAddress1}"
streetAddress2: "${address.streetAddress2}"
city: "${address.city}"
postalCode: "${address.postalCode}"
country: ${address.country}
phone: "${address.phone}"
}
defaultShippingAddress: {
companyName: "${address.companyName}"
streetAddress1: "${address.streetAddress1}"
streetAddress2: "${address.streetAddress2}"
city: "${address.city}"
postalCode: "${address.postalCode}"
country: ${address.country}
phone: "${address.phone}"
}
}){
user{
id
}
accountErrors{
code
message
}
}
}
`;
return cy.sendRequestWithQuery(mutation);
}
deleteCustomers(startsWith) {
this.getCustomers(startsWith).then(resp => {
if (resp.body.data.customers) {
const customers = resp.body.data.customers.edges;
customers.forEach(element => {
if (element.node.email.includes(startsWith)) {
this.deleteCustomer(element.node.id);
}
});
}
});
}
deleteCustomer(customerId) {
const mutation = `mutation{
customerDelete(id:"${customerId}"){
accountErrors{
code
message
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}
getCustomers(startsWith) {
const query = `query{
customers(first:100, filter: {
search: "${startsWith}"
}){
edges{
node{
id
email
}
}
}
}
`;
return cy.sendRequestWithQuery(query);
}
}
export default Customer;

60
cypress/api/Order.js Normal file
View file

@ -0,0 +1,60 @@
class Order {
markOrderAsPaid(orderId) {
const mutation = `mutation{
orderMarkAsPaid(id:"${orderId}"){
orderErrors{
message
}
}
}`;
cy.sendRequestWithQuery(mutation);
}
addProductToOrder(orderId, variantId, quantity = 1) {
const mutation = `mutation{
draftOrderLinesCreate(id:"${orderId}", input:{
quantity:${quantity}
variantId: "${variantId}"
}){
orderErrors{
message
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}
createDraftOrder(customerId, shippingMethodId, channelId) {
const mutation = `
mutation{
draftOrderCreate(input:{
user:"${customerId}"
shippingMethod:"${shippingMethodId}"
channel: "${channelId}"
}){
orderErrors{
message
}
order{
id
}
}
}
`;
return cy.sendRequestWithQuery(mutation);
}
completeOrder(orderId) {
const mutation = `mutation{
draftOrderComplete(id:"${orderId}"){
order{
id
}
orderErrors{
message
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}
}
export default Order;

55
cypress/api/Product.js Normal file
View file

@ -0,0 +1,55 @@
class Product {
getFirstProducts(first) {
const query = `query{
products(first:${first}){
edges{
node{
id
name
variants{
id
}
}
}
}
}
`;
return cy.sendRequestWithQuery(query);
}
updateChannelInProduct(productId, channelId) {
const mutation = `mutation{
productChannelListingUpdate(id:"${productId}", input:{
addChannels:{
channelId:"${channelId}"
isPublished: true
isAvailableForPurchase:true
visibleInListings:true
}
}){
product{
id
name
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}
updateChannelPriceInVariant(variantId, channelId) {
const mutation = `mutation{
productVariantChannelListingUpdate(id: "${variantId}", input:{
channelId: "${channelId}"
price: 10
costPrice: 10
}){
productChannelListingErrors{
message
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}
}
export default Product;

View file

@ -0,0 +1,97 @@
class ShippingMethod {
createShippingRate(name, shippingZone) {
const mutation = `
mutation{
shippingPriceCreate(input:{
name: "${name}"
shippingZone: "${shippingZone}"
type: PRICE
}){
shippingMethod{
id
}
}
}
`;
return cy.sendRequestWithQuery(mutation);
}
createShippingZone(name, country) {
const mutation = `
mutation{
shippingZoneCreate(input:{
name: "${name}"
countries: "${country}"
}){
shippingZone{
id
}
}
}
`;
return cy.sendRequestWithQuery(mutation);
}
addChannelToShippingMethod(shippingRateId, channelId) {
const mutation = `
mutation{
shippingMethodChannelListingUpdate(id:"${shippingRateId}", input:{
addChannels: {
channelId:"${channelId}"
price:10
}
}){
shippingMethod{
id
}
shippingErrors{
code
message
}
}
}
`;
return cy.sendRequestWithQuery(mutation);
}
deleteShippingZones(startsWith) {
this.getShippingZones().then(resp => {
if (resp.body.data.shippingZones) {
const shippingZone = resp.body.data.shippingZones.edges;
shippingZone.forEach(element => {
if (element.node.name.includes(startsWith)) {
this.deleteShippingZone(element.node.id);
}
});
}
});
}
deleteShippingZone(shippingZoneId) {
const mutation = `mutation{
shippingZoneDelete(id:"${shippingZoneId}"){
shippingErrors{
message
}
}
}
`;
return cy.sendRequestWithQuery(mutation);
}
getShippingZones() {
const query = `query{
shippingZones(first:100){
edges{
node{
name
id
}
}
}
}
`;
return cy.sendRequestWithQuery(query);
}
}
export default ShippingMethod;

View file

@ -1,12 +1,30 @@
import faker from "faker";
import Customer from "../api/Customer";
import Order from "../api/Order";
import Product from "../api/Product";
import ShippingMethod from "../api/ShippingMethod";
import { DASHBOARD_SELECTORS } from "../elements/dashboard/dashboard-selectors"; import { DASHBOARD_SELECTORS } from "../elements/dashboard/dashboard-selectors";
// <reference types="cypress" /> // <reference types="cypress" />
describe("User authorization", () => { describe("User authorization", () => {
const startsWith = "Cy-";
const customer = new Customer();
const product = new Product();
const order = new Order();
const shippingMethod = new ShippingMethod();
before(() => {
customer.deleteCustomers(startsWith);
shippingMethod.deleteShippingZones(startsWith);
});
beforeEach(() => { beforeEach(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
}); });
it("should all elements be visible on the dashboard", () => { xit("should all elements be visible on the dashboard", () => {
cy.visit("/"); cy.visit("/");
softAssertVisibility(DASHBOARD_SELECTORS.sales); softAssertVisibility(DASHBOARD_SELECTORS.sales);
softAssertVisibility(DASHBOARD_SELECTORS.orders); softAssertVisibility(DASHBOARD_SELECTORS.orders);
@ -17,17 +35,94 @@ describe("User authorization", () => {
softAssertVisibility(DASHBOARD_SELECTORS.productsOutOfStock); softAssertVisibility(DASHBOARD_SELECTORS.productsOutOfStock);
}); });
xit("aa", () => { it("should correct amount of orders be displayed", () => {
faker = require("faker");
const randomName = startsWith + faker.random.number();
const randomEmail = randomName + "@example.com";
product.getFirstProducts(3).then(productsResp => {
const productsList = productsResp.body.data.products.edges;
productsList.forEach(productElement => {
product.updateChannelInProduct(
"Q2hhbm5lbDoxNzk=",
productElement.node.id
);
const variants = productElement.node.variants;
variants.forEach(variant => {
product.updateChannelPriceInVariant(variant.id, "Q2hhbm5lbDoxNzk=");
});
});
cy.fixture("addresses").then(json => { cy.fixture("addresses").then(json => {
cy.createCustomer("Test9", "Test9", json.plAddress); customer
.createCustomer(randomEmail, randomName, json.plAddress)
.as("createCustomerResponse")
.then(resp => {
const customerId = resp.body.data.customerCreate.user.id;
shippingMethod
.createShippingZone(randomName, "PL")
.then(shippingZoneResp => {
shippingMethod
.createShippingRate(
randomName,
shippingZoneResp.body.data.shippingZoneCreate.shippingZone
.id
)
.then(rateResp => {
const shippingMethodId =
rateResp.body.data.shippingPriceCreate.shippingMethod.id;
shippingMethod
.addChannelToShippingMethod(
shippingMethodId,
"Q2hhbm5lbDoxNzk="
)
.then(shippingMethodResp => {
createReadyToFullfillOrder(
customerId,
shippingMethodId,
"Q2hhbm5lbDoxNzk=",
productsList
);
}); });
createChannel();
createRateShipping();
addChannelToProduct();
createOrder();
}); });
});
});
});
});
cy.visit("/");
softAssertMatch(DASHBOARD_SELECTORS.orders, /^0/);
softAssertMatch(DASHBOARD_SELECTORS.ordersReadyToFulfill, /^Brak/);
softAssertMatch(DASHBOARD_SELECTORS.paymentsWaitingForCapture, /^Brak/);
softAssertMatch(DASHBOARD_SELECTORS.productsOutOfStock, /^Brak/);
});
function createReadyToFullfillOrder(
customerId,
shippingMethodId,
channelId,
productsList
) {
order
.createDraftOrder(customerId, shippingMethodId, channelId)
.then(draftOrderResp => {
const orderId = draftOrderResp.body.data.draftOrderCreate.order.id;
productsList.forEach(productElement => {
productElement.node.variants.forEach(variantElement => {
order.addProductToOrder(orderId, variantElement.id);
});
});
order.markOrderAsPaid(orderId);
order.completeOrder(orderId);
});
}
function softAssertVisibility(selector) { function softAssertVisibility(selector) {
cy.get(selector).then(element => chai.softExpect(element).to.be.visible); cy.get(selector).then(element => chai.softExpect(element).to.be.visible);
} }
function softAssertMatch(selector, regexp) {
cy.get(selector)
.invoke("text")
.then(text =>
chai.softExpect(assert.match(text, regexp, "regexp matches"))
);
}
}); });

View file

@ -1,37 +0,0 @@
Cypress.Commands.add(
"createCustomer",
(email, name, address, isActive = false) => {
const mustation = `
mutation{
customerCreate(input:{
firstName: "${name}"
lastName: "${name}"
email: "${email}"
isActive: ${isActive}
defaultBillingAddress: {
companyName: "${address.companyName}"
streetAddress1: "${address.streetAddress1}"
streetAddress2: "${address.streetAddress2}"
city: "${address.city}"
postalCode: "${address.postalCode}"
country: ${address.country}
phone: "${address.phone}"
}
defaultShippingAddress: {
companyName: "${address.companyName}"
streetAddress1: "${address.streetAddress1}"
streetAddress2: "${address.streetAddress2}"
city: "${address.city}"
postalCode: "${address.postalCode}"
country: ${address.country}
phone: "${address.phone}"
}
}){
accountErrors{
code
}
}
}
`;
}
);

View file

@ -1,7 +1,5 @@
import "./user"; import "./user";
import "./softAsserations"; import "./softAsserations";
import "./customer";
import "./shippingMethod";
Cypress.Commands.add("clearSessionData", () => { Cypress.Commands.add("clearSessionData", () => {
// Because of known cypress bug, not all local storage data are cleared. // Because of known cypress bug, not all local storage data are cleared.
@ -20,3 +18,18 @@ Cypress.Commands.add("clearSessionData", () => {
} }
}); });
}); });
Cypress.Commands.add("sendRequestWithQuery", query =>
cy.request({
method: "POST",
body: {
method: "POST",
url: Cypress.env("API_URI"),
query
},
headers: {
Authorization: `JWT ${window.sessionStorage.getItem("auth")}`
},
url: Cypress.env("API_URI")
})
);

View file

@ -1,51 +0,0 @@
Cypress.Commands.add("createShippingRate", (name, shippingZone) => {
const mutation = `
mutation{
CreateShippingRate(input:{
maximumDeliveryDays: null
minimumDeliveryDays: null
name: "${name}"
shippingZone: "${shippingZone}"
type: "PRICE"
})
}
`;
return mutation;
});
Cypress.Commands.add("createShippingZone", (name, country) => {
const mutation = `
mutation{
shippingZoneCreate(input:{
name: "${name}"
countries: "${country}"
}){
shippingZone{
id
}
}
}
`;
return mutation;
});
Cypress.Commands.add("", (shippingRateId, channelId) => {
const mutation = `
mutation{
shippingMethodChannelListingUpdate(id:"${shippingRateId}", input:{
addChannels: {
channelId:"${channelId}"
}
}){
shippingMethod{
id
}
shippingErrors{
code
message
}
}
}
`;
return mutation;
});