created orders and products, missing data-testid
This commit is contained in:
parent
95be7b5163
commit
fe9f55ee81
17 changed files with 808 additions and 156 deletions
|
@ -1,55 +0,0 @@
|
||||||
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;
|
|
49
cypress/apiRequests/Attribute.js
Normal file
49
cypress/apiRequests/Attribute.js
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
class Attribute {
|
||||||
|
createAttribute(name) {
|
||||||
|
const mutation = `mutation{
|
||||||
|
attributeCreate(input:{
|
||||||
|
name:"${name}"
|
||||||
|
valueRequired:false
|
||||||
|
type:PRODUCT_TYPE
|
||||||
|
}){
|
||||||
|
attribute{
|
||||||
|
id
|
||||||
|
}
|
||||||
|
attributeErrors{
|
||||||
|
field
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(mutation);
|
||||||
|
}
|
||||||
|
|
||||||
|
getAttributes(first, search) {
|
||||||
|
const mutation = `query{
|
||||||
|
attributes(first:${first}, filter:{
|
||||||
|
search:"${search}"
|
||||||
|
}){
|
||||||
|
edges{
|
||||||
|
node{
|
||||||
|
id
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(mutation);
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteAttribute(attributeId) {
|
||||||
|
const mutation = `mutation{
|
||||||
|
attributeDelete(id:"${attributeId}"){
|
||||||
|
attributeErrors{
|
||||||
|
field
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(mutation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default Attribute;
|
43
cypress/apiRequests/Category.js
Normal file
43
cypress/apiRequests/Category.js
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
class Category {
|
||||||
|
createCategory(name, slug = name) {
|
||||||
|
const mutation = `mutation{
|
||||||
|
categoryCreate(input:{name:"${name}", slug: "${slug}"}){
|
||||||
|
productErrors{
|
||||||
|
field
|
||||||
|
message
|
||||||
|
}
|
||||||
|
category{
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(mutation);
|
||||||
|
}
|
||||||
|
getCategories(first, search) {
|
||||||
|
const mutation = `query{
|
||||||
|
categories(first:${first}, filter:{
|
||||||
|
search:"${search}"
|
||||||
|
}){
|
||||||
|
edges{
|
||||||
|
node{
|
||||||
|
id
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(mutation);
|
||||||
|
}
|
||||||
|
deleteCategory(categoryId) {
|
||||||
|
const mutation = `mutation{
|
||||||
|
categoryDelete(id:"${categoryId}"){
|
||||||
|
productErrors{
|
||||||
|
field
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(mutation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default Category;
|
74
cypress/apiRequests/Channels.js
Normal file
74
cypress/apiRequests/Channels.js
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
class Channels {
|
||||||
|
createChannel(isActive, name, slug, currencyCode) {
|
||||||
|
const createChannelMutation = `mutation{
|
||||||
|
channelCreate(input: {
|
||||||
|
isActive: ${isActive}
|
||||||
|
name: "${name}"
|
||||||
|
slug: "${slug}"
|
||||||
|
currencyCode: "${currencyCode}"
|
||||||
|
}){
|
||||||
|
channel{
|
||||||
|
id
|
||||||
|
name
|
||||||
|
slug
|
||||||
|
}
|
||||||
|
channelErrors{
|
||||||
|
code
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(createChannelMutation);
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteTestChannels(nameStartsWith) {
|
||||||
|
const getChannelsInfoQuery = `query{
|
||||||
|
channels{
|
||||||
|
name
|
||||||
|
id
|
||||||
|
isActive
|
||||||
|
slug
|
||||||
|
currencyCode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
cy.sendRequestWithQuery(getChannelsInfoQuery).then(resp => {
|
||||||
|
const channels = new Set(resp.body.data.channels);
|
||||||
|
if (channels) {
|
||||||
|
channels.forEach(element => {
|
||||||
|
if (element.name.startsWith(nameStartsWith)) {
|
||||||
|
const targetChannels = Array.from(channels).filter(function(
|
||||||
|
channel
|
||||||
|
) {
|
||||||
|
return (
|
||||||
|
element.currencyCode === channel.currencyCode &&
|
||||||
|
element.id !== channel.id
|
||||||
|
);
|
||||||
|
});
|
||||||
|
if (targetChannels[0]) {
|
||||||
|
this.deleteChannel(element.id, targetChannels[0].id);
|
||||||
|
channels.delete(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteChannel(channelId, targetChennelId) {
|
||||||
|
const deleteChannelMutation = `mutation{
|
||||||
|
channelDelete(id: "${channelId}", input:{
|
||||||
|
targetChannel: "${targetChennelId}"
|
||||||
|
}){
|
||||||
|
channel{
|
||||||
|
name
|
||||||
|
}
|
||||||
|
channelErrors{
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(deleteChannelMutation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default Channels;
|
70
cypress/apiRequests/Checkout.js
Normal file
70
cypress/apiRequests/Checkout.js
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
class Checkout {
|
||||||
|
createCheckout(channelSlug, email, productQuantity, variantsList) {
|
||||||
|
const lines = [];
|
||||||
|
variantsList.forEach(variant => {
|
||||||
|
lines.push(`{quantity:${productQuantity}
|
||||||
|
variantId:"${variant.id}"}`);
|
||||||
|
});
|
||||||
|
const mutation = `mutation{
|
||||||
|
checkoutCreate(input:{
|
||||||
|
channel:"${channelSlug}"
|
||||||
|
email:"${email}"
|
||||||
|
lines: [${lines.join()}]
|
||||||
|
}){
|
||||||
|
checkoutErrors{
|
||||||
|
field
|
||||||
|
message
|
||||||
|
}
|
||||||
|
created
|
||||||
|
checkout{
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(mutation);
|
||||||
|
}
|
||||||
|
addShippingMethod(checkoutId, shippingMethodId) {
|
||||||
|
const mutation = `mutation{
|
||||||
|
checkoutShippingMethodUpdate(checkoutId:"${checkoutId}",
|
||||||
|
shippingMethodId:"${shippingMethodId}"){
|
||||||
|
checkoutErrors{
|
||||||
|
message
|
||||||
|
field
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(mutation);
|
||||||
|
}
|
||||||
|
addPayment(checkoutId, gateway, token) {
|
||||||
|
const mutation = `mutation{
|
||||||
|
checkoutPaymentCreate(checkoutId:"${checkoutId}",
|
||||||
|
input:{
|
||||||
|
gateway: "${gateway}"
|
||||||
|
token:"${token}"
|
||||||
|
}){
|
||||||
|
paymentErrors{
|
||||||
|
field
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(mutation);
|
||||||
|
}
|
||||||
|
compliteCheckout(checkoutId) {
|
||||||
|
const mutation = `mutation{
|
||||||
|
checkoutComplete(checkoutId:"${checkoutId}"){
|
||||||
|
order{
|
||||||
|
id
|
||||||
|
}
|
||||||
|
confirmationNeeded
|
||||||
|
confirmationData
|
||||||
|
checkoutErrors{
|
||||||
|
field
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(mutation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default Checkout;
|
|
@ -28,6 +28,7 @@ export class Customer {
|
||||||
}){
|
}){
|
||||||
user{
|
user{
|
||||||
id
|
id
|
||||||
|
email
|
||||||
}
|
}
|
||||||
accountErrors{
|
accountErrors{
|
||||||
code
|
code
|
|
@ -7,7 +7,7 @@ class Order {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
cy.sendRequestWithQuery(mutation);
|
return cy.sendRequestWithQuery(mutation);
|
||||||
}
|
}
|
||||||
|
|
||||||
addProductToOrder(orderId, variantId, quantity = 1) {
|
addProductToOrder(orderId, variantId, quantity = 1) {
|
178
cypress/apiRequests/Product.js
Normal file
178
cypress/apiRequests/Product.js
Normal file
|
@ -0,0 +1,178 @@
|
||||||
|
class Product {
|
||||||
|
getFirstProducts(first, search) {
|
||||||
|
let filter = "";
|
||||||
|
if (search) {
|
||||||
|
filter = `, filter:{
|
||||||
|
search:"${search}"
|
||||||
|
}`;
|
||||||
|
}
|
||||||
|
const query = `query{
|
||||||
|
products(first:${first}${filter}){
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}){
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
createProduct(attributeId, name, productType, category) {
|
||||||
|
const mutation = `mutation{
|
||||||
|
productCreate(input:{
|
||||||
|
attributes:[{
|
||||||
|
id:"${attributeId}"
|
||||||
|
}]
|
||||||
|
name:"${name}"
|
||||||
|
productType:"${productType}"
|
||||||
|
category:"${category}"
|
||||||
|
}){
|
||||||
|
product{
|
||||||
|
id
|
||||||
|
}
|
||||||
|
productErrors{
|
||||||
|
field
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(mutation);
|
||||||
|
}
|
||||||
|
|
||||||
|
createVariant(
|
||||||
|
productId,
|
||||||
|
sku,
|
||||||
|
warehouseId,
|
||||||
|
quantity,
|
||||||
|
channelId,
|
||||||
|
price = 1,
|
||||||
|
costPrice = 1
|
||||||
|
) {
|
||||||
|
const mutation = `mutation{
|
||||||
|
productVariantBulkCreate(product:"${productId}", variants:{
|
||||||
|
attributes:[]
|
||||||
|
sku:"${sku}"
|
||||||
|
channelListings:{
|
||||||
|
channelId:"${channelId}"
|
||||||
|
price:"${price}"
|
||||||
|
costPrice:"${costPrice}"
|
||||||
|
}
|
||||||
|
stocks:{
|
||||||
|
warehouse:"${warehouseId}"
|
||||||
|
quantity:${quantity}
|
||||||
|
}
|
||||||
|
}){
|
||||||
|
productVariants{
|
||||||
|
id
|
||||||
|
name
|
||||||
|
}
|
||||||
|
bulkProductErrors{
|
||||||
|
field
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(mutation);
|
||||||
|
}
|
||||||
|
|
||||||
|
createTypeProduct(name, attributeId, slug = name) {
|
||||||
|
const mutation = `mutation{
|
||||||
|
productTypeCreate(input:{
|
||||||
|
name:"${name}"
|
||||||
|
slug: "${slug}"
|
||||||
|
isShippingRequired:true
|
||||||
|
productAttributes:"${attributeId}"
|
||||||
|
}){
|
||||||
|
productErrors{
|
||||||
|
field
|
||||||
|
message
|
||||||
|
}
|
||||||
|
productType{
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(mutation);
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteProduct(productId) {
|
||||||
|
const mutation = `mutation{
|
||||||
|
productDelete(id:"${productId}"){
|
||||||
|
productErrors{
|
||||||
|
field
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(mutation);
|
||||||
|
}
|
||||||
|
|
||||||
|
getProductTypes(first, search) {
|
||||||
|
const query = `query{
|
||||||
|
productTypes(first:${first}, filter:{
|
||||||
|
search:"${search}"
|
||||||
|
}){
|
||||||
|
edges{
|
||||||
|
node{
|
||||||
|
id
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteProductType(productTypeId) {
|
||||||
|
const mutation = `mutation{
|
||||||
|
productTypeDelete(id:"${productTypeId}"){
|
||||||
|
productErrors{
|
||||||
|
field
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(mutation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Product;
|
|
@ -32,13 +32,13 @@ class ShippingMethod {
|
||||||
return cy.sendRequestWithQuery(mutation);
|
return cy.sendRequestWithQuery(mutation);
|
||||||
}
|
}
|
||||||
|
|
||||||
addChannelToShippingMethod(shippingRateId, channelId) {
|
addChannelToShippingMethod(shippingRateId, channelId, price) {
|
||||||
const mutation = `
|
const mutation = `
|
||||||
mutation{
|
mutation{
|
||||||
shippingMethodChannelListingUpdate(id:"${shippingRateId}", input:{
|
shippingMethodChannelListingUpdate(id:"${shippingRateId}", input:{
|
||||||
addChannels: {
|
addChannels: {
|
||||||
channelId:"${channelId}"
|
channelId:"${channelId}"
|
||||||
price:10
|
price: ${price}
|
||||||
}
|
}
|
||||||
}){
|
}){
|
||||||
shippingMethod{
|
shippingMethod{
|
||||||
|
@ -54,19 +54,6 @@ class ShippingMethod {
|
||||||
return cy.sendRequestWithQuery(mutation);
|
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) {
|
deleteShippingZone(shippingZoneId) {
|
||||||
const mutation = `mutation{
|
const mutation = `mutation{
|
||||||
shippingZoneDelete(id:"${shippingZoneId}"){
|
shippingZoneDelete(id:"${shippingZoneId}"){
|
55
cypress/apiRequests/Warehouse.js
Normal file
55
cypress/apiRequests/Warehouse.js
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
class Warehouse {
|
||||||
|
createWarehouse(name, shippingZone, address, slug = name) {
|
||||||
|
const mutation = `mutation{
|
||||||
|
createWarehouse(input:{
|
||||||
|
name:"${name}"
|
||||||
|
slug:"${slug}"
|
||||||
|
shippingZones:"${shippingZone}"
|
||||||
|
address:{
|
||||||
|
streetAddress1: "${address.streetAddress1}"
|
||||||
|
streetAddress2: "${address.streetAddress2}"
|
||||||
|
city: "${address.city}"
|
||||||
|
postalCode: "${address.postalCode}"
|
||||||
|
country: ${address.country}
|
||||||
|
phone: "${address.phone}"
|
||||||
|
}
|
||||||
|
}){
|
||||||
|
warehouseErrors{
|
||||||
|
field
|
||||||
|
message
|
||||||
|
}
|
||||||
|
warehouse{
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(mutation);
|
||||||
|
}
|
||||||
|
getWarehouses(first, search) {
|
||||||
|
const query = `query{
|
||||||
|
warehouses(first:${first}, filter:{
|
||||||
|
search:"${search}"
|
||||||
|
}){
|
||||||
|
edges{
|
||||||
|
node{
|
||||||
|
id
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(query);
|
||||||
|
}
|
||||||
|
deleteWarehouse(warehouseId) {
|
||||||
|
const mutation = `mutation{
|
||||||
|
deleteWarehouse(id:"${warehouseId}"){
|
||||||
|
warehouseErrors{
|
||||||
|
field
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(mutation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default Warehouse;
|
4
cypress/elements/header/header-selectors.js
Normal file
4
cypress/elements/header/header-selectors.js
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
export const HEADER_SELECTORS = {
|
||||||
|
channelSelect: "[data-test-id='app-channel-select']",
|
||||||
|
channelSelectList: "[class*='MuiMenu-paper']"
|
||||||
|
};
|
|
@ -7,6 +7,7 @@
|
||||||
"postalCode": "53-346",
|
"postalCode": "53-346",
|
||||||
"country": "PL",
|
"country": "PL",
|
||||||
"countryArea": "Dolny Śląsk",
|
"countryArea": "Dolny Śląsk",
|
||||||
"phone": "123456787"
|
"phone": "123456787",
|
||||||
|
"currency": "PLN"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +0,0 @@
|
||||||
{
|
|
||||||
"name": "Using fixtures to represent data",
|
|
||||||
"email": "hello@cypress.io",
|
|
||||||
"body": "Fixtures are a great way to mock data for responses to routes"
|
|
||||||
}
|
|
|
@ -1,23 +1,29 @@
|
||||||
import faker from "faker";
|
import faker from "faker";
|
||||||
|
|
||||||
import Customer from "../api/Customer";
|
import Channels from "../apiRequests/Channels";
|
||||||
import Order from "../api/Order";
|
import Customer from "../apiRequests/Customer";
|
||||||
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";
|
||||||
|
import { HEADER_SELECTORS } from "../elements/header/header-selectors";
|
||||||
|
import OrdersUtils from "../utils/ordersUtils";
|
||||||
|
import ProductsUtils from "../utils/productsUtils";
|
||||||
|
import ShippingUtils from "../utils/shippingUtils";
|
||||||
|
|
||||||
// <reference types="cypress" />
|
// <reference types="cypress" />
|
||||||
describe("User authorization", () => {
|
describe("User authorization", () => {
|
||||||
const startsWith = "Cy-";
|
const startsWith = "Cy-";
|
||||||
|
|
||||||
const customer = new Customer();
|
const customer = new Customer();
|
||||||
const product = new Product();
|
const channels = new Channels();
|
||||||
const order = new Order();
|
const productsUtils = new ProductsUtils();
|
||||||
const shippingMethod = new ShippingMethod();
|
const shippingUtils = new ShippingUtils();
|
||||||
|
const ordersUtils = new OrdersUtils();
|
||||||
|
|
||||||
before(() => {
|
before(() => {
|
||||||
|
cy.clearSessionData().loginUserViaRequest();
|
||||||
customer.deleteCustomers(startsWith);
|
customer.deleteCustomers(startsWith);
|
||||||
shippingMethod.deleteShippingZones(startsWith);
|
shippingUtils.deleteShipping(startsWith);
|
||||||
|
productsUtils.deleteProducts(startsWith);
|
||||||
|
channels.deleteTestChannels(startsWith);
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -36,84 +42,87 @@ describe("User authorization", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should correct amount of orders be displayed", () => {
|
it("should correct amount of orders be displayed", () => {
|
||||||
faker = require("faker");
|
|
||||||
const randomName = startsWith + faker.random.number();
|
const randomName = startsWith + faker.random.number();
|
||||||
const randomEmail = randomName + "@example.com";
|
const randomEmail = randomName + "@example.com";
|
||||||
product.getFirstProducts(3).then(productsResp => {
|
const randomNameProductOutOfStock = `${startsWith}${faker.random.number()}`;
|
||||||
const productsList = productsResp.body.data.products.edges;
|
const shippingPrice = 12;
|
||||||
productsList.forEach(productElement => {
|
const productPrice = 22;
|
||||||
product.updateChannelInProduct(
|
cy.fixture("addresses").then(json => {
|
||||||
"Q2hhbm5lbDoxNzk=",
|
channels
|
||||||
productElement.node.id
|
.createChannel(true, randomName, randomName, json.plAddress.currency)
|
||||||
);
|
.then(channelsResp => {
|
||||||
const variants = productElement.node.variants;
|
const channelId = channelsResp.body.data.channelCreate.channel.id;
|
||||||
variants.forEach(variant => {
|
const channelSlug = channelsResp.body.data.channelCreate.channel.slug;
|
||||||
product.updateChannelPriceInVariant(variant.id, "Q2hhbm5lbDoxNzk=");
|
customer
|
||||||
|
.createCustomer(randomEmail, randomName, json.plAddress)
|
||||||
|
.then(resp => {
|
||||||
|
const customerId = resp.body.data.customerCreate.user.id;
|
||||||
|
const customerEmail = resp.body.data.customerCreate.user.email;
|
||||||
|
shippingUtils
|
||||||
|
.createShipping(
|
||||||
|
channelId,
|
||||||
|
randomName,
|
||||||
|
json.plAddress,
|
||||||
|
shippingPrice
|
||||||
|
)
|
||||||
|
.then(() => {
|
||||||
|
const shippingId = shippingUtils.getShippingMethodId();
|
||||||
|
const warehouseId = shippingUtils.getWarehouseId();
|
||||||
|
productsUtils
|
||||||
|
.createTypeAttributeAndCategoryForProduct(randomName)
|
||||||
|
.then(() => {
|
||||||
|
const productTypeId = productsUtils.getProductTypeId();
|
||||||
|
const attributeId = productsUtils.getAttributeId();
|
||||||
|
const categoryId = productsUtils.getCategoryId();
|
||||||
|
productsUtils
|
||||||
|
.createProductInChannel(
|
||||||
|
randomName,
|
||||||
|
channelId,
|
||||||
|
warehouseId,
|
||||||
|
10,
|
||||||
|
productTypeId,
|
||||||
|
attributeId,
|
||||||
|
categoryId,
|
||||||
|
productPrice
|
||||||
|
)
|
||||||
|
.then(() => {
|
||||||
|
const variantsList = productsUtils.getCreatedVariants();
|
||||||
|
ordersUtils.createReadyToFullfillOrder(
|
||||||
|
customerId,
|
||||||
|
shippingId,
|
||||||
|
channelId,
|
||||||
|
variantsList
|
||||||
|
);
|
||||||
|
ordersUtils.createWaitingForCaptureOrder(
|
||||||
|
channelSlug,
|
||||||
|
customerEmail,
|
||||||
|
variantsList,
|
||||||
|
shippingId
|
||||||
|
);
|
||||||
|
});
|
||||||
|
productsUtils.createProductInChannel(
|
||||||
|
randomNameProductOutOfStock,
|
||||||
|
channelId,
|
||||||
|
warehouseId,
|
||||||
|
0,
|
||||||
|
productTypeId,
|
||||||
|
attributeId,
|
||||||
|
categoryId,
|
||||||
|
productPrice
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
cy.fixture("addresses").then(json => {
|
|
||||||
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
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
cy.visit("/");
|
cy.visit("/");
|
||||||
softAssertMatch(DASHBOARD_SELECTORS.orders, /^0/);
|
cy.get(HEADER_SELECTORS.channelSelect)
|
||||||
softAssertMatch(DASHBOARD_SELECTORS.ordersReadyToFulfill, /^Brak/);
|
.click()
|
||||||
softAssertMatch(DASHBOARD_SELECTORS.paymentsWaitingForCapture, /^Brak/);
|
.get(HEADER_SELECTORS.channelSelectList)
|
||||||
softAssertMatch(DASHBOARD_SELECTORS.productsOutOfStock, /^Brak/);
|
.contains(randomName)
|
||||||
|
.click();
|
||||||
});
|
});
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
46
cypress/utils/ordersUtils.js
Normal file
46
cypress/utils/ordersUtils.js
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
import Checkout from "../apiRequests/Checkout";
|
||||||
|
import Order from "../apiRequests/Order";
|
||||||
|
|
||||||
|
class OrdersUtils {
|
||||||
|
createWaitingForCaptureOrder(
|
||||||
|
channelSlug,
|
||||||
|
email,
|
||||||
|
variantsList,
|
||||||
|
shippingMethodId
|
||||||
|
) {
|
||||||
|
const checkout = new Checkout();
|
||||||
|
return checkout
|
||||||
|
.createCheckout(channelSlug, email, 1, variantsList)
|
||||||
|
.then(createCheckoutResp => {
|
||||||
|
const checkoutId =
|
||||||
|
createCheckoutResp.body.data.checkoutCreate.checkout.id;
|
||||||
|
return checkout
|
||||||
|
.addShippingMethod(checkoutId, shippingMethodId)
|
||||||
|
.then(() =>
|
||||||
|
checkout
|
||||||
|
.addPayment(checkoutId, "mirumee.payments.dummy", "not-charged")
|
||||||
|
.then(() => checkout.compliteCheckout(checkoutId))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
createReadyToFullfillOrder(
|
||||||
|
customerId,
|
||||||
|
shippingMethodId,
|
||||||
|
channelId,
|
||||||
|
variantsList
|
||||||
|
) {
|
||||||
|
const order = new Order();
|
||||||
|
return order
|
||||||
|
.createDraftOrder(customerId, shippingMethodId, channelId)
|
||||||
|
.then(draftOrderResp => {
|
||||||
|
const orderId = draftOrderResp.body.data.draftOrderCreate.order.id;
|
||||||
|
variantsList.forEach(variantElement => {
|
||||||
|
order.addProductToOrder(orderId, variantElement.id);
|
||||||
|
});
|
||||||
|
return order
|
||||||
|
.markOrderAsPaid(orderId)
|
||||||
|
.then(() => order.completeOrder(orderId));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default OrdersUtils;
|
124
cypress/utils/productsUtils.js
Normal file
124
cypress/utils/productsUtils.js
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
import Attribute from "../apiRequests/Attribute";
|
||||||
|
import Category from "../apiRequests/Category";
|
||||||
|
import Product from "../apiRequests/Product";
|
||||||
|
|
||||||
|
class ProductsUtils {
|
||||||
|
createdVariantId;
|
||||||
|
productTypeId;
|
||||||
|
attributeId;
|
||||||
|
categoryId;
|
||||||
|
|
||||||
|
updateChannelInProduct(productsList, channelId) {
|
||||||
|
const product = new Product();
|
||||||
|
productsList.forEach(productElement => {
|
||||||
|
product.updateChannelInProduct(productElement.node.id, channelId);
|
||||||
|
const variants = productElement.node.variants;
|
||||||
|
variants.forEach(variant => {
|
||||||
|
product.updateChannelPriceInVariant(variant.id, channelId);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
createProductInChannel(
|
||||||
|
name,
|
||||||
|
channelId,
|
||||||
|
warehouseId,
|
||||||
|
quantityInWarehouse,
|
||||||
|
productTypeId,
|
||||||
|
attributeId,
|
||||||
|
categoryId,
|
||||||
|
price
|
||||||
|
) {
|
||||||
|
const product = new Product();
|
||||||
|
return product
|
||||||
|
.createProduct(attributeId, name, productTypeId, categoryId)
|
||||||
|
.then(createProductResp => {
|
||||||
|
const productId = createProductResp.body.data.productCreate.product.id;
|
||||||
|
return product.updateChannelInProduct(productId, channelId).then(() =>
|
||||||
|
product
|
||||||
|
.createVariant(
|
||||||
|
productId,
|
||||||
|
name,
|
||||||
|
warehouseId,
|
||||||
|
quantityInWarehouse,
|
||||||
|
channelId,
|
||||||
|
price
|
||||||
|
)
|
||||||
|
.then(createVariantResp => {
|
||||||
|
this.createdVariantId =
|
||||||
|
createVariantResp.body.data.productVariantBulkCreate.productVariants;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
createTypeAttributeAndCategoryForProduct(name) {
|
||||||
|
const attribute = new Attribute();
|
||||||
|
const category = new Category();
|
||||||
|
const product = new Product();
|
||||||
|
return attribute.createAttribute(name).then(createAttributeResp => {
|
||||||
|
this.attributeId =
|
||||||
|
createAttributeResp.body.data.attributeCreate.attribute.id;
|
||||||
|
return product
|
||||||
|
.createTypeProduct(name, this.attributeId)
|
||||||
|
.then(createTypeProductResp => {
|
||||||
|
this.productTypeId =
|
||||||
|
createTypeProductResp.body.data.productTypeCreate.productType.id;
|
||||||
|
return category.createCategory(name).then(categoryResp => {
|
||||||
|
this.categoryId = categoryResp.body.data.categoryCreate.category.id;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getCreatedVariants() {
|
||||||
|
return this.createdVariantId;
|
||||||
|
}
|
||||||
|
getProductTypeId() {
|
||||||
|
return this.productTypeId;
|
||||||
|
}
|
||||||
|
getAttributeId() {
|
||||||
|
return this.attributeId;
|
||||||
|
}
|
||||||
|
getCategoryId() {
|
||||||
|
return this.categoryId;
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteProducts(startsWith) {
|
||||||
|
const product = new Product();
|
||||||
|
const attribute = new Attribute();
|
||||||
|
const category = new Category();
|
||||||
|
product.getProductTypes(100, startsWith).then(resp => {
|
||||||
|
const productTypes = resp.body.data.productTypes.edges;
|
||||||
|
productTypes.forEach(productType => {
|
||||||
|
if (productType.node.name.includes(startsWith)) {
|
||||||
|
product.deleteProductType(productType.node.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
attribute.getAttributes(100, startsWith).then(resp => {
|
||||||
|
const attributes = resp.body.data.attributes.edges;
|
||||||
|
attributes.forEach(attributeElement => {
|
||||||
|
if (attributeElement.node.name.includes(startsWith)) {
|
||||||
|
attribute.deleteAttribute(attributeElement.node.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
category.getCategories(100, startsWith).then(resp => {
|
||||||
|
const categories = resp.body.data.categories.edges;
|
||||||
|
categories.forEach(categoryElement => {
|
||||||
|
if (categoryElement.node.name.includes(startsWith)) {
|
||||||
|
category.deleteCategory(categoryElement.node.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
product.getFirstProducts(100, startsWith).then(getProductResp => {
|
||||||
|
const products = getProductResp.body.data.products.edges;
|
||||||
|
products.forEach(productElement => {
|
||||||
|
if (productElement.node.name.includes(startsWith)) {
|
||||||
|
product.deleteProducts(productElement.node.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default productsUtils;
|
71
cypress/utils/shippingUtils.js
Normal file
71
cypress/utils/shippingUtils.js
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
import ShippingMethod from "../apiRequests/ShippingMethod";
|
||||||
|
import Warehouse from "../apiRequests/Warehouse";
|
||||||
|
class ShippingUtils {
|
||||||
|
shippingMethodId;
|
||||||
|
shippingZoneId;
|
||||||
|
warehouseId;
|
||||||
|
|
||||||
|
createShipping(channelId, name, address, price) {
|
||||||
|
const shippingMethod = new ShippingMethod();
|
||||||
|
const warehouse = new Warehouse();
|
||||||
|
return shippingMethod
|
||||||
|
.createShippingZone(name, address.country)
|
||||||
|
.then(shippingZoneResp => {
|
||||||
|
this.shippingZoneId =
|
||||||
|
shippingZoneResp.body.data.shippingZoneCreate.shippingZone.id;
|
||||||
|
return warehouse
|
||||||
|
.createWarehouse(name, this.shippingZoneId, address)
|
||||||
|
.then(createWarehouseResp => {
|
||||||
|
this.warehouseId =
|
||||||
|
createWarehouseResp.body.data.createWarehouse.warehouse.id;
|
||||||
|
return shippingMethod
|
||||||
|
.createShippingRate(name, this.shippingZoneId)
|
||||||
|
.then(rateResp => {
|
||||||
|
this.shippingMethodId =
|
||||||
|
rateResp.body.data.shippingPriceCreate.shippingMethod.id;
|
||||||
|
return shippingMethod.addChannelToShippingMethod(
|
||||||
|
this.shippingMethodId,
|
||||||
|
channelId,
|
||||||
|
price
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getShippingMethodId() {
|
||||||
|
return this.shippingMethodId;
|
||||||
|
}
|
||||||
|
|
||||||
|
getShippingZoneId() {
|
||||||
|
return this.shippingZoneId;
|
||||||
|
}
|
||||||
|
|
||||||
|
getWarehouseId() {
|
||||||
|
return this.warehouseId;
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteShipping(startsWith) {
|
||||||
|
const shippingMethod = new ShippingMethod();
|
||||||
|
const warehouse = new Warehouse();
|
||||||
|
shippingMethod.getShippingZones().then(resp => {
|
||||||
|
if (resp.body.data.shippingZones) {
|
||||||
|
const shippingZone = resp.body.data.shippingZones.edges;
|
||||||
|
shippingZone.forEach(element => {
|
||||||
|
if (element.node.name.includes(startsWith)) {
|
||||||
|
shippingMethod.deleteShippingZone(element.node.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
warehouse.getWarehouses(100, startsWith).then(resp => {
|
||||||
|
const warehouses = resp.body.data.warehouses.edges;
|
||||||
|
warehouses.forEach(warehouseElement => {
|
||||||
|
if (warehouseElement.node.name.includes(startsWith)) {
|
||||||
|
warehouse.deleteWarehouse(warehouseElement.node.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default ShippingUtils;
|
Loading…
Reference in a new issue