Skip to content

Commit

Permalink
Fix e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jwm0 committed Apr 23, 2021
1 parent 88b7da6 commit 95c61ce
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
8 changes: 4 additions & 4 deletions cypress/apiRequests/HomePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ export function getSalesForChannel(channelSlug, period) {
}`;
return cy.sendRequestWithQuery(query);
}
export function getOrdersForChannel(channelSlug, created) {
export function getOrdersForChannel(channelSlug, { gte, lte }) {
const query = `query{
orders(created: ${created}, channel:"${channelSlug}"){
orders(filter: { created: { gte: "${gte}", lte: "${lte}" } }, channel:"${channelSlug}"){
totalCount
}
}`;
return cy.sendRequestWithQuery(query);
}
export function getOrdersWithStatus(status, channelSlug) {
const query = `query{
orders(status: ${status}, channel:"${channelSlug}"){
orders(filter: { status: ${status} }, channel:"${channelSlug}"){
totalCount
}
}`;
return cy.sendRequestWithQuery(query);
}
export function getProductsOutOfStock(channelSlug) {
const query = `query{
products(stockAvailability: OUT_OF_STOCK, channel:"${channelSlug}"){
products(filter: { stockAvailability: OUT_OF_STOCK, channel:"${channelSlug}" }){
totalCount
}
}`;
Expand Down
5 changes: 4 additions & 1 deletion cypress/utils/homePageUtils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as homePage from "../apiRequests/HomePage";
import { getDatePeriod } from "./misc";

export function getOrdersReadyToFulfill(channelSlug) {
return homePage
Expand All @@ -21,7 +22,9 @@ export function getSalesAmount(channelSlug) {
.its("body.data.ordersTotal.gross.amount");
}
export function getTodaysOrders(channelSlug) {
const today = getDatePeriod(1);

return homePage
.getOrdersForChannel(channelSlug, "TODAY")
.getOrdersForChannel(channelSlug, today)
.its("body.data.orders.totalCount");
}
16 changes: 16 additions & 0 deletions cypress/utils/misc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import moment from "moment-timezone";

export function getDatePeriod(days) {
if (days < 1) {
return {};
}

const end = moment().startOf("day");
const start = end.subtract(days - 1);
const format = "YYYY-MM-DD";

return {
gte: start.format(format),
lte: end.format(format)
};
}

0 comments on commit 95c61ce

Please sign in to comment.