Saleor 1745 tests for discounts sales (#998)
* test plan for sales - discounts * create sale * passing tests for sales * tests for collections * remove eslint diable in sales tests * remove eslint-disable * move shared selectors * move shared selectors * fix indentation in requests * add formatDate function * remove moment * remove moment
This commit is contained in:
parent
fc597a7a7f
commit
746ce8b95f
31 changed files with 864 additions and 522 deletions
|
@ -1,39 +1,39 @@
|
|||
export function createAttribute(name, attributeValues = ["value"]) {
|
||||
const values = attributeValues.map(element => `{name:"${element}"}`);
|
||||
const mutation = `mutation{
|
||||
attributeCreate(input:{
|
||||
name:"${name}"
|
||||
valueRequired:false
|
||||
type:PRODUCT_TYPE
|
||||
values: [${values}]
|
||||
}){
|
||||
attribute{
|
||||
id
|
||||
name
|
||||
values{name}
|
||||
}
|
||||
attributeErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
attributeCreate(input:{
|
||||
name:"${name}"
|
||||
valueRequired:false
|
||||
type:PRODUCT_TYPE
|
||||
values: [${values}]
|
||||
}){
|
||||
attribute{
|
||||
id
|
||||
name
|
||||
values{name}
|
||||
}
|
||||
attributeErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
||||
export function getAttributes(first, search) {
|
||||
const mutation = `query{
|
||||
attributes(first:${first}, filter:{
|
||||
search:"${search}"
|
||||
}){
|
||||
edges{
|
||||
node{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}`;
|
||||
attributes(first:${first}, filter:{
|
||||
search:"${search}"
|
||||
}){
|
||||
edges{
|
||||
node{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy
|
||||
.sendRequestWithQuery(mutation)
|
||||
.then(resp => resp.body.data.attributes.edges);
|
||||
|
@ -41,12 +41,12 @@ export function getAttributes(first, search) {
|
|||
|
||||
export function deleteAttribute(attributeId) {
|
||||
const mutation = `mutation{
|
||||
attributeDelete(id:"${attributeId}"){
|
||||
attributeErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
attributeDelete(id:"${attributeId}"){
|
||||
attributeErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
|
|
@ -1,42 +1,42 @@
|
|||
export function createCategory(name, slug = name) {
|
||||
const mutation = `mutation{
|
||||
categoryCreate(input:{name:"${name}", slug: "${slug}"}){
|
||||
productErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
category{
|
||||
id
|
||||
}
|
||||
}
|
||||
}`;
|
||||
categoryCreate(input:{name:"${name}", slug: "${slug}"}){
|
||||
productErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
category{
|
||||
id
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
export function getCategories(first, search) {
|
||||
const mutation = `query{
|
||||
categories(first:${first}, filter:{
|
||||
search:"${search}"
|
||||
}){
|
||||
edges{
|
||||
node{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}`;
|
||||
categories(first:${first}, filter:{
|
||||
search:"${search}"
|
||||
}){
|
||||
edges{
|
||||
node{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy
|
||||
.sendRequestWithQuery(mutation)
|
||||
.then(resp => resp.body.data.categories.edges);
|
||||
}
|
||||
export function deleteCategory(categoryId) {
|
||||
const mutation = `mutation{
|
||||
categoryDelete(id:"${categoryId}"){
|
||||
productErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
categoryDelete(id:"${categoryId}"){
|
||||
productErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
|
|
@ -1,50 +1,49 @@
|
|||
export function 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
|
||||
}
|
||||
}
|
||||
}`;
|
||||
channelCreate(input: {
|
||||
isActive: ${isActive}
|
||||
name: "${name}"
|
||||
slug: "${slug}"
|
||||
currencyCode: "${currencyCode}"
|
||||
}){
|
||||
channel{
|
||||
id
|
||||
name
|
||||
slug
|
||||
}
|
||||
channelErrors{
|
||||
code
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(createChannelMutation);
|
||||
}
|
||||
export function getChannels() {
|
||||
const getChannelsInfoQuery = `query{
|
||||
channels{
|
||||
name
|
||||
id
|
||||
isActive
|
||||
slug
|
||||
currencyCode
|
||||
}
|
||||
channels{
|
||||
name
|
||||
id
|
||||
isActive
|
||||
slug
|
||||
currencyCode
|
||||
}
|
||||
`;
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(getChannelsInfoQuery);
|
||||
}
|
||||
|
||||
export function deleteChannel(channelId, targetChannelId) {
|
||||
const deleteChannelMutation = `mutation{
|
||||
channelDelete(id: "${channelId}", input:{
|
||||
targetChannel: "${targetChannelId}"
|
||||
}){
|
||||
channel{
|
||||
name
|
||||
}
|
||||
channelErrors{
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
channelDelete(id: "${channelId}", input:{
|
||||
targetChannel: "${targetChannelId}"
|
||||
}){
|
||||
channel{
|
||||
name
|
||||
}
|
||||
channelErrors{
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(deleteChannelMutation);
|
||||
}
|
||||
|
|
|
@ -9,63 +9,63 @@ export function createCheckout(
|
|||
variantId:"${variant.id}"}`
|
||||
);
|
||||
const mutation = `mutation{
|
||||
checkoutCreate(input:{
|
||||
channel:"${channelSlug}"
|
||||
email:"${email}"
|
||||
lines: [${lines.join()}]
|
||||
}){
|
||||
checkoutErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
created
|
||||
checkout{
|
||||
id
|
||||
}
|
||||
}
|
||||
}`;
|
||||
checkoutCreate(input:{
|
||||
channel:"${channelSlug}"
|
||||
email:"${email}"
|
||||
lines: [${lines.join()}]
|
||||
}){
|
||||
checkoutErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
created
|
||||
checkout{
|
||||
id
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
export function addShippingMethod(checkoutId, shippingMethodId) {
|
||||
const mutation = `mutation{
|
||||
checkoutShippingMethodUpdate(checkoutId:"${checkoutId}",
|
||||
shippingMethodId:"${shippingMethodId}"){
|
||||
checkoutErrors{
|
||||
message
|
||||
field
|
||||
}
|
||||
}
|
||||
}`;
|
||||
checkoutShippingMethodUpdate(checkoutId:"${checkoutId}",
|
||||
shippingMethodId:"${shippingMethodId}"){
|
||||
checkoutErrors{
|
||||
message
|
||||
field
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
export function addPayment(checkoutId, gateway, token) {
|
||||
const mutation = `mutation{
|
||||
checkoutPaymentCreate(checkoutId:"${checkoutId}",
|
||||
input:{
|
||||
gateway: "${gateway}"
|
||||
token:"${token}"
|
||||
}){
|
||||
paymentErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
checkoutPaymentCreate(checkoutId:"${checkoutId}",
|
||||
input:{
|
||||
gateway: "${gateway}"
|
||||
token:"${token}"
|
||||
}){
|
||||
paymentErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
export function completeCheckout(checkoutId) {
|
||||
const mutation = `mutation{
|
||||
checkoutComplete(checkoutId:"${checkoutId}"){
|
||||
order{
|
||||
id
|
||||
}
|
||||
confirmationNeeded
|
||||
confirmationData
|
||||
checkoutErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
checkoutComplete(checkoutId:"${checkoutId}"){
|
||||
order{
|
||||
id
|
||||
}
|
||||
confirmationNeeded
|
||||
confirmationData
|
||||
checkoutErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
|
|
@ -5,30 +5,30 @@ export function getCollections(search) {
|
|||
}`
|
||||
: "";
|
||||
const query = `query{
|
||||
collections(first:100 ${filter}){
|
||||
edges{
|
||||
node{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
collections(first:100 ${filter}){
|
||||
edges{
|
||||
node{
|
||||
id
|
||||
name
|
||||
}
|
||||
}`;
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy
|
||||
.sendRequestWithQuery(query)
|
||||
.then(resp => resp.body.data.collections.edges);
|
||||
}
|
||||
export function deleteCollection(collectionId) {
|
||||
const mutation = `mutation{
|
||||
collectionDelete(id:"${collectionId}"){
|
||||
collection{
|
||||
id
|
||||
}
|
||||
collectionErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
collectionDelete(id:"${collectionId}"){
|
||||
collection{
|
||||
id
|
||||
}
|
||||
collectionErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
|
|
@ -1,41 +1,40 @@
|
|||
export function 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
|
||||
email
|
||||
}
|
||||
accountErrors{
|
||||
code
|
||||
message
|
||||
}
|
||||
}
|
||||
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
|
||||
email
|
||||
}
|
||||
accountErrors{
|
||||
code
|
||||
message
|
||||
}
|
||||
}
|
||||
`;
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
||||
|
@ -54,29 +53,28 @@ export function deleteCustomers(startsWith) {
|
|||
|
||||
export function deleteCustomer(customerId) {
|
||||
const mutation = `mutation{
|
||||
customerDelete(id:"${customerId}"){
|
||||
accountErrors{
|
||||
code
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
customerDelete(id:"${customerId}"){
|
||||
accountErrors{
|
||||
code
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
||||
export function getCustomers(startsWith) {
|
||||
const query = `query{
|
||||
customers(first:100, filter: {
|
||||
search: "${startsWith}"
|
||||
}){
|
||||
edges{
|
||||
node{
|
||||
id
|
||||
email
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
customers(first:100, filter: {
|
||||
search: "${startsWith}"
|
||||
}){
|
||||
edges{
|
||||
node{
|
||||
id
|
||||
email
|
||||
}
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(query);
|
||||
}
|
||||
|
|
|
@ -1,34 +1,34 @@
|
|||
export function getSalesForChannel(channelSlug, period) {
|
||||
const query = `query{
|
||||
ordersTotal(period: ${period}, channel:"${channelSlug}"){
|
||||
gross{
|
||||
amount
|
||||
}
|
||||
}
|
||||
}`;
|
||||
ordersTotal(period: ${period}, channel:"${channelSlug}"){
|
||||
gross{
|
||||
amount
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(query);
|
||||
}
|
||||
export function getOrdersForChannel(channelSlug, created) {
|
||||
const query = `query{
|
||||
orders(created: ${created}, channel:"${channelSlug}"){
|
||||
totalCount
|
||||
}
|
||||
}`;
|
||||
orders(created: ${created}, channel:"${channelSlug}"){
|
||||
totalCount
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(query);
|
||||
}
|
||||
export function getOrdersWithStatus(status, channelSlug) {
|
||||
const query = `query{
|
||||
orders(status: ${status}, channel:"${channelSlug}"){
|
||||
totalCount
|
||||
}
|
||||
}`;
|
||||
orders(status: ${status}, channel:"${channelSlug}"){
|
||||
totalCount
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(query);
|
||||
}
|
||||
export function getProductsOutOfStock(channelSlug) {
|
||||
const query = `query{
|
||||
products(stockAvailability: OUT_OF_STOCK, channel:"${channelSlug}"){
|
||||
totalCount
|
||||
}
|
||||
}`;
|
||||
products(stockAvailability: OUT_OF_STOCK, channel:"${channelSlug}"){
|
||||
totalCount
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(query);
|
||||
}
|
||||
|
|
|
@ -1,57 +1,55 @@
|
|||
export function markOrderAsPaid(orderId) {
|
||||
const mutation = `mutation{
|
||||
orderMarkAsPaid(id:"${orderId}"){
|
||||
orderErrors{
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
orderMarkAsPaid(id:"${orderId}"){
|
||||
orderErrors{
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
||||
export function addProductToOrder(orderId, variantId, quantity = 1) {
|
||||
const mutation = `mutation{
|
||||
draftOrderLinesCreate(id:"${orderId}", input:{
|
||||
quantity:${quantity}
|
||||
variantId: "${variantId}"
|
||||
}){
|
||||
orderErrors{
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
draftOrderLinesCreate(id:"${orderId}", input:{
|
||||
quantity:${quantity}
|
||||
variantId: "${variantId}"
|
||||
}){
|
||||
orderErrors{
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
||||
export function createDraftOrder(customerId, shippingMethodId, channelId) {
|
||||
const mutation = `
|
||||
mutation{
|
||||
draftOrderCreate(input:{
|
||||
user:"${customerId}"
|
||||
shippingMethod:"${shippingMethodId}"
|
||||
channel: "${channelId}"
|
||||
}){
|
||||
orderErrors{
|
||||
message
|
||||
}
|
||||
order{
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
const mutation = `mutation{
|
||||
draftOrderCreate(input:{
|
||||
user:"${customerId}"
|
||||
shippingMethod:"${shippingMethodId}"
|
||||
channel: "${channelId}"
|
||||
}){
|
||||
orderErrors{
|
||||
message
|
||||
}
|
||||
order{
|
||||
id
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
export function completeOrder(orderId) {
|
||||
const mutation = `mutation{
|
||||
draftOrderComplete(id:"${orderId}"){
|
||||
order{
|
||||
id
|
||||
}
|
||||
orderErrors{
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
draftOrderComplete(id:"${orderId}"){
|
||||
order{
|
||||
id
|
||||
}
|
||||
orderErrors{
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
|
|
@ -7,18 +7,17 @@ export function getFirstProducts(first, search) {
|
|||
}`
|
||||
: "";
|
||||
const query = `query{
|
||||
products(first:${first}${filter}){
|
||||
edges{
|
||||
node{
|
||||
id
|
||||
name
|
||||
variants{
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
products(first:${first}${filter}){
|
||||
edges{
|
||||
node{
|
||||
id
|
||||
name
|
||||
variants{
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy
|
||||
.sendRequestWithQuery(query)
|
||||
.then(resp => resp.body.data.products.edges);
|
||||
|
@ -32,57 +31,58 @@ export function updateChannelInProduct({
|
|||
visibleInListings = true
|
||||
}) {
|
||||
const mutation = `mutation{
|
||||
productChannelListingUpdate(id:"${productId}",
|
||||
input:{
|
||||
addChannels:{
|
||||
channelId:"${channelId}"
|
||||
isPublished:${isPublished}
|
||||
isAvailableForPurchase:${isAvailableForPurchase}
|
||||
visibleInListings:${visibleInListings}
|
||||
}
|
||||
}){
|
||||
product{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}`;
|
||||
productChannelListingUpdate(id:"${productId}",
|
||||
input:{
|
||||
addChannels:{
|
||||
channelId:"${channelId}"
|
||||
isPublished:${isPublished}
|
||||
isAvailableForPurchase:${isAvailableForPurchase}
|
||||
visibleInListings:${visibleInListings}
|
||||
}
|
||||
}){
|
||||
product{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
||||
export function updateChannelPriceInVariant(variantId, channelId) {
|
||||
const mutation = `mutation{
|
||||
productVariantChannelListingUpdate(id: "${variantId}", input: {
|
||||
channelId: "${channelId}"
|
||||
price: 10
|
||||
costPrice: 10
|
||||
}){
|
||||
productChannelListingErrors{
|
||||
message
|
||||
productVariantChannelListingUpdate(id: "${variantId}", input: {
|
||||
channelId: "${channelId}"
|
||||
price: 10
|
||||
costPrice: 10
|
||||
}){
|
||||
productChannelListingErrors{
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
} `;
|
||||
} `;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
export function createProduct(attributeId, name, productType, category) {
|
||||
const mutation = `mutation{
|
||||
productCreate(input:{
|
||||
attributes:[{
|
||||
id:"${attributeId}"
|
||||
}]
|
||||
name:"${name}"
|
||||
productType:"${productType}"
|
||||
category:"${category}"
|
||||
}){
|
||||
product{
|
||||
id
|
||||
}
|
||||
productErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
productCreate(input:{
|
||||
attributes:[{
|
||||
id:"${attributeId}"
|
||||
}]
|
||||
name:"${name}"
|
||||
productType:"${productType}"
|
||||
category:"${category}"
|
||||
}){
|
||||
product{
|
||||
id
|
||||
name
|
||||
}
|
||||
}`;
|
||||
productErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
||||
|
@ -113,71 +113,71 @@ export function createVariant({
|
|||
);
|
||||
|
||||
const mutation = `mutation{
|
||||
productVariantBulkCreate(product: "${productId}", variants: {
|
||||
attributes: []
|
||||
sku: "${sku}"
|
||||
${channelListings}
|
||||
${stocks}
|
||||
}) {
|
||||
productVariants{
|
||||
id
|
||||
name
|
||||
}
|
||||
bulkProductErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
productVariantBulkCreate(product: "${productId}", variants: {
|
||||
attributes: []
|
||||
sku: "${sku}"
|
||||
${channelListings}
|
||||
${stocks}
|
||||
}) {
|
||||
productVariants{
|
||||
id
|
||||
name
|
||||
}
|
||||
bulkProductErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
||||
export function createTypeProduct(name, attributeId, slug = name) {
|
||||
const mutation = `mutation{
|
||||
productTypeCreate(input: {
|
||||
name: "${name}"
|
||||
slug: "${slug}"
|
||||
isShippingRequired: true
|
||||
productAttributes: "${attributeId}"
|
||||
variantAttributes: "${attributeId}"
|
||||
}){
|
||||
productErrors{
|
||||
field
|
||||
message
|
||||
productTypeCreate(input: {
|
||||
name: "${name}"
|
||||
slug: "${slug}"
|
||||
isShippingRequired: true
|
||||
productAttributes: "${attributeId}"
|
||||
variantAttributes: "${attributeId}"
|
||||
}){
|
||||
productErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
productType{
|
||||
id
|
||||
}
|
||||
}
|
||||
productType{
|
||||
id
|
||||
}
|
||||
}
|
||||
} `;
|
||||
} `;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
||||
export function deleteProduct(productId) {
|
||||
const mutation = `mutation{
|
||||
productDelete(id: "${productId}"){
|
||||
productErrors{
|
||||
field
|
||||
message
|
||||
productDelete(id: "${productId}"){
|
||||
productErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
} `;
|
||||
} `;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
||||
export function getProductTypes(first, search) {
|
||||
const query = `query{
|
||||
productTypes(first:${first}, filter:{
|
||||
search:"${search}"
|
||||
}){
|
||||
edges{
|
||||
node{
|
||||
id
|
||||
name
|
||||
}
|
||||
productTypes(first:${first}, filter:{
|
||||
search:"${search}"
|
||||
}){
|
||||
edges{
|
||||
node{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}`;
|
||||
}
|
||||
}`;
|
||||
return cy
|
||||
.sendRequestWithQuery(query)
|
||||
.then(resp => resp.body.data.productTypes.edges);
|
||||
|
@ -185,12 +185,12 @@ export function getProductTypes(first, search) {
|
|||
|
||||
export function deleteProductType(productTypeId) {
|
||||
const mutation = `mutation{
|
||||
productTypeDelete(id:"${productTypeId}"){
|
||||
productErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
productTypeDelete(id:"${productTypeId}"){
|
||||
productErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}`;
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
|
35
cypress/apiRequests/Sales.js
Normal file
35
cypress/apiRequests/Sales.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
import { getValueWithDefault } from "./utils/Utils";
|
||||
|
||||
export function getSales(first, searchQuery) {
|
||||
const filter = getValueWithDefault(
|
||||
searchQuery,
|
||||
`, filter:{
|
||||
search:"${searchQuery}"
|
||||
}`
|
||||
);
|
||||
const query = `query{
|
||||
sales(first:
|
||||
${first} ${filter}){
|
||||
edges{
|
||||
node{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy
|
||||
.sendRequestWithQuery(query)
|
||||
.then(resp => resp.body.data.sales.edges);
|
||||
}
|
||||
export function deleteSale(saleId) {
|
||||
const mutation = `mutation{
|
||||
saleDelete(id:"${saleId}"){
|
||||
discountErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
|
@ -1,55 +1,49 @@
|
|||
export function createShippingRate(name, shippingZone) {
|
||||
const mutation = `
|
||||
mutation{
|
||||
shippingPriceCreate(input:{
|
||||
name: "${name}"
|
||||
shippingZone: "${shippingZone}"
|
||||
type: PRICE
|
||||
}){
|
||||
shippingMethod{
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
const mutation = `mutation{
|
||||
shippingPriceCreate(input:{
|
||||
name: "${name}"
|
||||
shippingZone: "${shippingZone}"
|
||||
type: PRICE
|
||||
}){
|
||||
shippingMethod{
|
||||
id
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
||||
export function createShippingZone(name, country) {
|
||||
const mutation = `
|
||||
mutation{
|
||||
shippingZoneCreate(input:{
|
||||
name: "${name}"
|
||||
countries: "${country}"
|
||||
}){
|
||||
shippingZone{
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
const mutation = `mutation{
|
||||
shippingZoneCreate(input:{
|
||||
name: "${name}"
|
||||
countries: "${country}"
|
||||
}){
|
||||
shippingZone{
|
||||
id
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
||||
export function addChannelToShippingMethod(shippingRateId, channelId, price) {
|
||||
const mutation = `
|
||||
mutation{
|
||||
shippingMethodChannelListingUpdate(id:"${shippingRateId}", input:{
|
||||
addChannels: {
|
||||
channelId:"${channelId}"
|
||||
price: ${price}
|
||||
}
|
||||
}){
|
||||
shippingMethod{
|
||||
id
|
||||
}
|
||||
shippingErrors{
|
||||
code
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
const mutation = `mutation{
|
||||
shippingMethodChannelListingUpdate(id:"${shippingRateId}", input:{
|
||||
addChannels: {
|
||||
channelId:"${channelId}"
|
||||
price: ${price}
|
||||
}
|
||||
}){
|
||||
shippingMethod{
|
||||
id
|
||||
}
|
||||
shippingErrors{
|
||||
code
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,55 +1,55 @@
|
|||
export function 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
|
||||
name
|
||||
}
|
||||
}
|
||||
}`;
|
||||
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
|
||||
name
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
export function getWarehouses(first, search) {
|
||||
const query = `query{
|
||||
warehouses(first:${first}, filter:{
|
||||
search:"${search}"
|
||||
}){
|
||||
edges{
|
||||
node{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}`;
|
||||
warehouses(first:${first}, filter:{
|
||||
search:"${search}"
|
||||
}){
|
||||
edges{
|
||||
node{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy
|
||||
.sendRequestWithQuery(query)
|
||||
.then(resp => resp.body.data.warehouses.edges);
|
||||
}
|
||||
export function deleteWarehouse(warehouseId) {
|
||||
const mutation = `mutation{
|
||||
deleteWarehouse(id:"${warehouseId}"){
|
||||
warehouseErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
deleteWarehouse(id:"${warehouseId}"){
|
||||
warehouseErrors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
export function getCollection(collectionId, channelSlug) {
|
||||
const query = `query Collection{
|
||||
collection(id: "${collectionId}", channel: "${channelSlug}") {
|
||||
id
|
||||
slug
|
||||
name
|
||||
products(first:100){
|
||||
totalCount
|
||||
edges{
|
||||
node{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
collection(id: "${collectionId}", channel: "${channelSlug}") {
|
||||
id
|
||||
slug
|
||||
name
|
||||
products(first:100){
|
||||
totalCount
|
||||
edges{
|
||||
node{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}`;
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(query, "token");
|
||||
}
|
||||
|
|
|
@ -1,37 +1,37 @@
|
|||
export function getProductDetails(productId, channelId) {
|
||||
const query = `fragment BasicProductFields on Product {
|
||||
id
|
||||
name
|
||||
}
|
||||
id
|
||||
name
|
||||
}
|
||||
|
||||
fragment Price on TaxedMoney {
|
||||
gross {
|
||||
amount
|
||||
currency
|
||||
fragment Price on TaxedMoney {
|
||||
gross {
|
||||
amount
|
||||
currency
|
||||
}
|
||||
}
|
||||
|
||||
fragment ProductVariantFields on ProductVariant {
|
||||
id
|
||||
sku
|
||||
name
|
||||
pricing {
|
||||
price {
|
||||
...Price
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fragment ProductVariantFields on ProductVariant {
|
||||
id
|
||||
sku
|
||||
name
|
||||
pricing {
|
||||
price {
|
||||
...Price
|
||||
}
|
||||
query ProductDetails{
|
||||
product(id: "${productId}", channel: "${channelId}") {
|
||||
...BasicProductFields
|
||||
variants {
|
||||
...ProductVariantFields
|
||||
}
|
||||
isAvailable
|
||||
isAvailableForPurchase
|
||||
availableForPurchase
|
||||
}
|
||||
|
||||
query ProductDetails{
|
||||
product(id: "${productId}", channel: "${channelId}") {
|
||||
...BasicProductFields
|
||||
variants {
|
||||
...ProductVariantFields
|
||||
}
|
||||
isAvailable
|
||||
isAvailableForPurchase
|
||||
availableForPurchase
|
||||
}
|
||||
}`;
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(query, "token");
|
||||
}
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
export function searchInShop(searchQuery) {
|
||||
const query = `query SearchProducts {
|
||||
products(channel: "default-channel", filter:{
|
||||
search: "${searchQuery}"
|
||||
}, first:10){
|
||||
totalCount
|
||||
edges{
|
||||
node{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
products(channel: "default-channel", filter:{
|
||||
search: "${searchQuery}"
|
||||
},
|
||||
first:10){
|
||||
totalCount
|
||||
edges{
|
||||
node{
|
||||
id
|
||||
name
|
||||
}
|
||||
}`;
|
||||
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(query, "token");
|
||||
}
|
||||
|
|
4
cypress/elements/catalog/assign-products.js
Normal file
4
cypress/elements/catalog/assign-products.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
export const ASSIGN_PRODUCTS_SELECTORS = {
|
||||
searchInput: "[name='query']",
|
||||
tableRow: "[data-test-id='assign-product-table-row']"
|
||||
};
|
16
cypress/elements/channels/menage-channel-availability.js
Normal file
16
cypress/elements/channels/menage-channel-availability.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
export const MENAGE_CHANNEL_AVAILABILITY = {
|
||||
availableManageButton:
|
||||
"[data-test-id='channels-availiability-manage-button']",
|
||||
channelsAvailabilityForm:
|
||||
"[data-test-id='manage-products-channels-availiability-list']",
|
||||
channelAvailabilityColumn:
|
||||
"[data-test='availability'][data-test-availability='true']",
|
||||
channelAvailabilityList: "ul[role='menu']",
|
||||
assignedChannels: "[data-test='channel-availability-item']",
|
||||
publishedRadioButtons: "[name*='isPublished']",
|
||||
availableForPurchaseRadioButtons: "[name*='isAvailableForPurchase']",
|
||||
radioButtonsValueTrue: "[value='true']",
|
||||
radioButtonsValueFalse: "[value='false']",
|
||||
visibleInListingsButton: "[name*='visibleInListings']",
|
||||
allChannelsInput: "[name='allChannels']"
|
||||
};
|
11
cypress/elements/discounts/sales.js
Normal file
11
cypress/elements/discounts/sales.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
export const SALES_SELECTORS = {
|
||||
createSaleButton: "[data-test-id='create-sale']",
|
||||
nameInput: "[name='name']",
|
||||
percentageOption: "[value='PERCENTAGE']",
|
||||
fixedOption: "[value='FIXED']",
|
||||
discountValue: "[name='value']",
|
||||
startDateInput: "[name='startDate']",
|
||||
saveButton: "[data-test='button-bar-confirm']",
|
||||
productsTab: "[data-test-id='products-tab']",
|
||||
assignProducts: "[data-test-id='assign-products']"
|
||||
};
|
|
@ -1,4 +1,5 @@
|
|||
export const BUTTON_SELECTORS = {
|
||||
back: '[data-test="back"]',
|
||||
submit: '[data-test="submit"]'
|
||||
submit: '[data-test="submit"]',
|
||||
checkbox: "[type='checkbox']"
|
||||
};
|
||||
|
|
179
cypress/integration/discounts/sales.js
Normal file
179
cypress/integration/discounts/sales.js
Normal file
|
@ -0,0 +1,179 @@
|
|||
// <reference types="cypress" />
|
||||
|
||||
import faker from "faker";
|
||||
|
||||
import { updateChannelInProduct } from "../../apiRequests/Product";
|
||||
import {
|
||||
assignProducts,
|
||||
createSale,
|
||||
discountOptions
|
||||
} from "../../steps/salesSteps";
|
||||
import { urlList } from "../../url/urlList";
|
||||
import * as channelsUtils from "../../utils/channelsUtils";
|
||||
import * as productsUtils from "../../utils/productsUtils";
|
||||
import { deleteSalesStartsWith } from "../../utils/salesUtils";
|
||||
import {
|
||||
createShipping,
|
||||
deleteShippingStartsWith
|
||||
} from "../../utils/shippingUtils";
|
||||
import { getProductPrice } from "../../utils/storeFront/storeFrontProductUtils";
|
||||
|
||||
describe("Sales discounts", () => {
|
||||
const startsWith = "Cy-";
|
||||
|
||||
let productType;
|
||||
let attribute;
|
||||
let category;
|
||||
let defaultChannel;
|
||||
let warehouse;
|
||||
|
||||
before(() => {
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
channelsUtils.deleteChannelsStartsWith(startsWith);
|
||||
deleteSalesStartsWith(startsWith);
|
||||
productsUtils.deleteProductsStartsWith(startsWith);
|
||||
deleteShippingStartsWith(startsWith);
|
||||
|
||||
const name = `${startsWith}${faker.random.number()}`;
|
||||
productsUtils
|
||||
.createTypeAttributeAndCategoryForProduct(name)
|
||||
.then(
|
||||
({
|
||||
productType: productTypeResp,
|
||||
attribute: attributeResp,
|
||||
category: categoryResp
|
||||
}) => {
|
||||
productType = productTypeResp;
|
||||
attribute = attributeResp;
|
||||
category = categoryResp;
|
||||
|
||||
channelsUtils.getDefaultChannel();
|
||||
}
|
||||
)
|
||||
.then(channel => {
|
||||
defaultChannel = channel;
|
||||
cy.fixture("addresses");
|
||||
})
|
||||
.then(addresses => {
|
||||
createShipping({
|
||||
channelId: defaultChannel.id,
|
||||
name,
|
||||
address: addresses.plAddress,
|
||||
price: 100
|
||||
});
|
||||
})
|
||||
.then(({ warehouse: warehouseResp }) => {
|
||||
warehouse = warehouseResp;
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
});
|
||||
|
||||
it("should create percentage discount", () => {
|
||||
const saleName = `${startsWith}${faker.random.number()}`;
|
||||
const discountValue = 50;
|
||||
const productPrice = 100;
|
||||
|
||||
productsUtils
|
||||
.createProductInChannel({
|
||||
name: saleName,
|
||||
channelId: defaultChannel.id,
|
||||
warehouseId: warehouse.id,
|
||||
productTypeId: productType.id,
|
||||
attributeId: attribute.id,
|
||||
categoryId: category.id,
|
||||
price: productPrice
|
||||
})
|
||||
.then(({ product: productResp }) => {
|
||||
cy.visit(urlList.sales);
|
||||
const product = productResp;
|
||||
createSale({
|
||||
saleName,
|
||||
channelName: defaultChannel.name,
|
||||
discountValue,
|
||||
discountOption: discountOptions.PERCENTAGE
|
||||
});
|
||||
assignProducts(product.name);
|
||||
getProductPrice(product.id, defaultChannel.slug);
|
||||
})
|
||||
.then(price => {
|
||||
const expectedPrice = (productPrice * discountValue) / 100;
|
||||
expect(expectedPrice).to.be.eq(price);
|
||||
});
|
||||
});
|
||||
|
||||
it("should create fixed price discount", () => {
|
||||
const saleName = `${startsWith}${faker.random.number()}`;
|
||||
const discountValue = 50;
|
||||
const productPrice = 100;
|
||||
|
||||
productsUtils
|
||||
.createProductInChannel({
|
||||
name: saleName,
|
||||
channelId: defaultChannel.id,
|
||||
warehouseId: warehouse.id,
|
||||
productTypeId: productType.id,
|
||||
attributeId: attribute.id,
|
||||
categoryId: category.id,
|
||||
price: productPrice
|
||||
})
|
||||
.then(({ product: productResp }) => {
|
||||
cy.visit(urlList.sales);
|
||||
const product = productResp;
|
||||
createSale({
|
||||
saleName,
|
||||
channelName: defaultChannel.name,
|
||||
discountValue,
|
||||
discountOption: discountOptions.FIXED
|
||||
});
|
||||
assignProducts(product.name);
|
||||
getProductPrice(product.id, defaultChannel.slug);
|
||||
})
|
||||
.then(price => {
|
||||
const expectedPrice = productPrice - discountValue;
|
||||
expect(expectedPrice).to.be.eq(price);
|
||||
});
|
||||
});
|
||||
|
||||
it("should not displayed discount not assign to channel", () => {
|
||||
const saleName = `${startsWith}${faker.random.number()}`;
|
||||
let channel;
|
||||
let product;
|
||||
const discountValue = 50;
|
||||
const productPrice = 100;
|
||||
|
||||
channelsUtils
|
||||
.createChannel({ name: saleName })
|
||||
.then(channelResp => (channel = channelResp));
|
||||
productsUtils
|
||||
.createProductInChannel({
|
||||
name: saleName,
|
||||
channelId: defaultChannel.id,
|
||||
warehouseId: warehouse.id,
|
||||
productTypeId: productType.id,
|
||||
attributeId: attribute.id,
|
||||
categoryId: category.id,
|
||||
price: productPrice
|
||||
})
|
||||
.then(({ product: productResp }) => {
|
||||
product = productResp;
|
||||
updateChannelInProduct({
|
||||
productId: product.id,
|
||||
channelId: channel.id
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
cy.visit(urlList.sales);
|
||||
createSale({
|
||||
saleName,
|
||||
channelName: channel.name,
|
||||
discountValue
|
||||
});
|
||||
assignProducts(product.name);
|
||||
getProductPrice(product.id, defaultChannel.slug);
|
||||
})
|
||||
.then(price => expect(price).to.equal(productPrice));
|
||||
});
|
||||
});
|
57
cypress/steps/salesSteps.js
Normal file
57
cypress/steps/salesSteps.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
import { ASSIGN_PRODUCTS_SELECTORS } from "../elements/catalog/assign-products";
|
||||
import { MENAGE_CHANNEL_AVAILABILITY } from "../elements/channels/menage-channel-availability";
|
||||
import { SALES_SELECTORS } from "../elements/discounts/sales";
|
||||
import { BUTTON_SELECTORS } from "../elements/shared/button-selectors";
|
||||
import { formatDate } from "../support/formatDate";
|
||||
|
||||
export const discountOptions = {
|
||||
PERCENTAGE: SALES_SELECTORS.percentageOption,
|
||||
FIXED: SALES_SELECTORS.fixedOption
|
||||
};
|
||||
|
||||
export function createSale({
|
||||
saleName,
|
||||
channelName,
|
||||
discountValue = 10,
|
||||
discountOption = discountOptions.PERCENTAGE
|
||||
}) {
|
||||
const todaysDate = formatDate(new Date());
|
||||
|
||||
cy.get(SALES_SELECTORS.createSaleButton)
|
||||
.click()
|
||||
.get(SALES_SELECTORS.nameInput)
|
||||
.type(saleName)
|
||||
.get(discountOption)
|
||||
.click()
|
||||
.get(MENAGE_CHANNEL_AVAILABILITY.availableManageButton)
|
||||
.click()
|
||||
.get(MENAGE_CHANNEL_AVAILABILITY.allChannelsInput)
|
||||
.click()
|
||||
.get(MENAGE_CHANNEL_AVAILABILITY.channelsAvailabilityForm)
|
||||
.contains(channelName)
|
||||
.click()
|
||||
.get(BUTTON_SELECTORS.submit)
|
||||
.click()
|
||||
.get(SALES_SELECTORS.discountValue)
|
||||
.type(discountValue)
|
||||
.get(SALES_SELECTORS.startDateInput)
|
||||
.type(todaysDate);
|
||||
cy.addAliasToGraphRequest("SaleCreate");
|
||||
cy.get(SALES_SELECTORS.saveButton).click();
|
||||
cy.wait("@SaleCreate");
|
||||
}
|
||||
|
||||
export function assignProducts(productName) {
|
||||
cy.get(SALES_SELECTORS.productsTab)
|
||||
.click()
|
||||
.get(SALES_SELECTORS.assignProducts)
|
||||
.click()
|
||||
.get(ASSIGN_PRODUCTS_SELECTORS.searchInput)
|
||||
.type(productName);
|
||||
cy.contains(ASSIGN_PRODUCTS_SELECTORS.tableRow, productName)
|
||||
.find(BUTTON_SELECTORS.checkbox)
|
||||
.click();
|
||||
cy.addAliasToGraphRequest("SaleCataloguesAdd");
|
||||
cy.get(BUTTON_SELECTORS.submit).click();
|
||||
cy.wait("@SaleCataloguesAdd");
|
||||
}
|
12
cypress/support/formatDate.js
Normal file
12
cypress/support/formatDate.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
export function formatDate(date) {
|
||||
const day = getPeriodValue(date, { day: "2-digit" });
|
||||
const month = getPeriodValue(date, { month: "2-digit" });
|
||||
const year = getPeriodValue(date, { year: "numeric" });
|
||||
|
||||
return new Array(year, month, day).join("-");
|
||||
}
|
||||
|
||||
function getPeriodValue(date, option) {
|
||||
const formatter = new Intl.DateTimeFormat("en-us", option);
|
||||
return formatter.format(date);
|
||||
}
|
|
@ -6,6 +6,7 @@ export const urlList = {
|
|||
orders: "orders/",
|
||||
products: "products/",
|
||||
warehouses: "warehouses/",
|
||||
sales: "discounts/sales/",
|
||||
collections: "collections/"
|
||||
};
|
||||
export const productDetailsUrl = productId => `${urlList.products}${productId}`;
|
||||
|
|
5
cypress/utils/salesUtils.js
Normal file
5
cypress/utils/salesUtils.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
import { deleteSale, getSales } from "../apiRequests/Sales";
|
||||
|
||||
export function deleteSalesStartsWith(startsWith) {
|
||||
cy.deleteElementsStartsWith(deleteSale, getSales, startsWith, "sales");
|
||||
}
|
|
@ -18,7 +18,7 @@ export const isProductVisibleInSearchResult = (resp, productName) => {
|
|||
);
|
||||
};
|
||||
|
||||
export const getProductVariants = (productId, channelSlug) =>
|
||||
export const getProductVariants = (productId, channelSlug) => {
|
||||
getProductDetails(productId, channelSlug).then(resp => {
|
||||
const variantsList = resp.body.data.product.variants;
|
||||
return variantsList.map(element => ({
|
||||
|
@ -26,3 +26,9 @@ export const getProductVariants = (productId, channelSlug) =>
|
|||
price: element.pricing.price.gross.amount
|
||||
}));
|
||||
});
|
||||
};
|
||||
|
||||
export const getProductPrice = (productId, channelSlug) =>
|
||||
getProductDetails(productId, channelSlug).then(
|
||||
resp => resp.body.data.product.variants[0].pricing.price.gross.amount
|
||||
);
|
||||
|
|
|
@ -165,7 +165,10 @@ const AssignProductDialog: React.FC<AssignProductDialogProps> = props => {
|
|||
);
|
||||
|
||||
return (
|
||||
<TableRow key={product.id}>
|
||||
<TableRow
|
||||
key={product.id}
|
||||
data-test-id="assign-product-table-row"
|
||||
>
|
||||
<TableCellAvatar
|
||||
className={classes.avatar}
|
||||
thumbnail={maybe(() => product.thumbnail.url)}
|
||||
|
@ -202,6 +205,7 @@ const AssignProductDialog: React.FC<AssignProductDialogProps> = props => {
|
|||
<FormattedMessage {...buttonMessages.back} />
|
||||
</Button>
|
||||
<ConfirmButton
|
||||
data-test="submit"
|
||||
transitionState={confirmButtonState}
|
||||
color="primary"
|
||||
variant="contained"
|
||||
|
|
|
@ -38,17 +38,19 @@ interface TabProps<T> {
|
|||
children?: React.ReactNode;
|
||||
isActive: boolean;
|
||||
changeTab: (index: T) => void;
|
||||
testId?: string;
|
||||
}
|
||||
|
||||
export function Tab<T>(value: T) {
|
||||
const Component: React.FC<TabProps<T>> = props => {
|
||||
const { children, isActive, changeTab } = props;
|
||||
const { children, isActive, changeTab, testId } = props;
|
||||
|
||||
const classes = useStyles(props);
|
||||
|
||||
return (
|
||||
<Typography
|
||||
component="span"
|
||||
data-test-id={testId}
|
||||
className={classNames({
|
||||
[classes.root]: true,
|
||||
[classes.active]: isActive
|
||||
|
|
|
@ -98,7 +98,11 @@ const DiscountProducts: React.FC<SaleProductsProps> = props => {
|
|||
description: "section header"
|
||||
})}
|
||||
toolbar={
|
||||
<Button color="primary" onClick={onProductAssign}>
|
||||
<Button
|
||||
color="primary"
|
||||
onClick={onProductAssign}
|
||||
data-test-id="assign-products"
|
||||
>
|
||||
<FormattedMessage
|
||||
defaultMessage="Assign products"
|
||||
description="button"
|
||||
|
|
|
@ -208,6 +208,7 @@ const SaleDetailsPage: React.FC<SaleDetailsPageProps> = ({
|
|||
)}
|
||||
</CollectionsTab>
|
||||
<ProductsTab
|
||||
testId="products-tab"
|
||||
isActive={activeTab === SaleDetailsPageTab.products}
|
||||
changeTab={onTabClick}
|
||||
>
|
||||
|
|
|
@ -54,7 +54,12 @@ const SaleListPage: React.FC<SaleListPageProps> = ({
|
|||
return (
|
||||
<Container>
|
||||
<PageHeader title={intl.formatMessage(sectionNames.sales)}>
|
||||
<Button onClick={onAdd} variant="contained" color="primary">
|
||||
<Button
|
||||
onClick={onAdd}
|
||||
variant="contained"
|
||||
color="primary"
|
||||
data-test-id="create-sale"
|
||||
>
|
||||
<FormattedMessage defaultMessage="Create Sale" description="button" />
|
||||
</Button>
|
||||
</PageHeader>
|
||||
|
|
|
@ -73441,6 +73441,7 @@ exports[`Storyshots Views / Discounts / Sale details collections 1`] = `
|
|||
</span>
|
||||
<span
|
||||
class="MuiTypography-root-id Tab-root-id MuiTypography-body1-id"
|
||||
data-test-id="products-tab"
|
||||
>
|
||||
Products (4)
|
||||
</span>
|
||||
|
@ -74796,6 +74797,7 @@ exports[`Storyshots Views / Discounts / Sale details default 1`] = `
|
|||
</span>
|
||||
<span
|
||||
class="MuiTypography-root-id Tab-root-id MuiTypography-body1-id"
|
||||
data-test-id="products-tab"
|
||||
>
|
||||
Products (4)
|
||||
</span>
|
||||
|
@ -76156,6 +76158,7 @@ exports[`Storyshots Views / Discounts / Sale details form errors 1`] = `
|
|||
</span>
|
||||
<span
|
||||
class="MuiTypography-root-id Tab-root-id MuiTypography-body1-id"
|
||||
data-test-id="products-tab"
|
||||
>
|
||||
Products (4)
|
||||
</span>
|
||||
|
@ -77538,6 +77541,7 @@ exports[`Storyshots Views / Discounts / Sale details loading 1`] = `
|
|||
</span>
|
||||
<span
|
||||
class="MuiTypography-root-id Tab-root-id MuiTypography-body1-id"
|
||||
data-test-id="products-tab"
|
||||
>
|
||||
Products (…)
|
||||
</span>
|
||||
|
@ -78925,6 +78929,7 @@ exports[`Storyshots Views / Discounts / Sale details products 1`] = `
|
|||
</span>
|
||||
<span
|
||||
class="MuiTypography-root-id Tab-root-id Tab-active-id MuiTypography-body1-id"
|
||||
data-test-id="products-tab"
|
||||
>
|
||||
Products (4)
|
||||
</span>
|
||||
|
@ -78948,6 +78953,7 @@ exports[`Storyshots Views / Discounts / Sale details products 1`] = `
|
|||
>
|
||||
<button
|
||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-text-id MuiButton-textPrimary-id"
|
||||
data-test-id="assign-products"
|
||||
tabindex="0"
|
||||
type="button"
|
||||
>
|
||||
|
@ -79968,6 +79974,7 @@ exports[`Storyshots Views / Discounts / Sale list default 1`] = `
|
|||
>
|
||||
<button
|
||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
||||
data-test-id="create-sale"
|
||||
tabindex="0"
|
||||
type="button"
|
||||
>
|
||||
|
@ -80658,6 +80665,7 @@ exports[`Storyshots Views / Discounts / Sale list loading 1`] = `
|
|||
>
|
||||
<button
|
||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
||||
data-test-id="create-sale"
|
||||
tabindex="0"
|
||||
type="button"
|
||||
>
|
||||
|
@ -81102,6 +81110,7 @@ exports[`Storyshots Views / Discounts / Sale list no channels 1`] = `
|
|||
>
|
||||
<button
|
||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
||||
data-test-id="create-sale"
|
||||
tabindex="0"
|
||||
type="button"
|
||||
>
|
||||
|
@ -81792,6 +81801,7 @@ exports[`Storyshots Views / Discounts / Sale list no data 1`] = `
|
|||
>
|
||||
<button
|
||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
||||
data-test-id="create-sale"
|
||||
tabindex="0"
|
||||
type="button"
|
||||
>
|
||||
|
|
Loading…
Reference in a new issue