
* Update schema, remove transaction specific files * Merge `.transaction` queries and mutations into regular files * Merge OrderDetails fragments * Remove usage of `.transaction` graphl types * Update fixtures * Remove usage of useFlag, remove duplicated queries & mutations * Fix displayed event type for INFO * Remove type alias from order/types.ts, remove type casting * Fix failing tests * Add preview label and better description in Channel settings * Update button in GrantRefund page * Fix missing data-test-id * add e2e for capture transactions in orders * creates tests for transactions order view switched on --------- Co-authored-by: Jonatan Witoszek <jonatan.witoszek@saleor.io> Co-authored-by: wojteknowacki <wojciech.nowacki@saleor.io>
205 lines
4 KiB
JavaScript
205 lines
4 KiB
JavaScript
import { getDefaultAddress, getValueWithDefault } from "./utils/Utils";
|
|
|
|
export function markOrderAsPaid(orderId) {
|
|
const mutation = `mutation{
|
|
orderMarkAsPaid(id:"${orderId}"){
|
|
errors{
|
|
message
|
|
}
|
|
order{
|
|
id
|
|
number
|
|
lines{
|
|
id
|
|
}
|
|
total{
|
|
gross{
|
|
amount
|
|
currency
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}`;
|
|
return cy.sendRequestWithQuery(mutation).its("body.data.orderMarkAsPaid");
|
|
}
|
|
|
|
export function updateOrdersSettings(automaticallyConfirmAllNewOrders = true) {
|
|
const mutation = `mutation{
|
|
orderSettingsUpdate(input:{
|
|
automaticallyConfirmAllNewOrders: ${automaticallyConfirmAllNewOrders}
|
|
}){
|
|
errors{
|
|
field
|
|
message
|
|
}
|
|
}
|
|
}`;
|
|
return cy.sendRequestWithQuery(mutation);
|
|
}
|
|
|
|
export function addProductToOrder(orderId, variantId, quantity = 1) {
|
|
const mutation = `mutation{
|
|
orderLinesCreate(id:"${orderId}", input:{
|
|
quantity:${quantity}
|
|
variantId: "${variantId}"
|
|
}){
|
|
order{
|
|
shippingMethods{
|
|
id
|
|
name
|
|
}
|
|
}
|
|
errors{
|
|
message
|
|
}
|
|
}
|
|
}`;
|
|
return cy.sendRequestWithQuery(mutation).its("body.data.orderLinesCreate");
|
|
}
|
|
|
|
export function createDraftOrder({ customerId, channelId, address }) {
|
|
const user = getValueWithDefault(customerId, `user:"${customerId}"`);
|
|
|
|
const mutation = `mutation{
|
|
draftOrderCreate(input:{
|
|
${user}
|
|
channelId: "${channelId}"
|
|
${getDefaultAddress(address, "shippingAddress")}
|
|
${getDefaultAddress(address, "billingAddress")}
|
|
}){
|
|
errors{
|
|
message
|
|
}
|
|
order{
|
|
id
|
|
number
|
|
id
|
|
shippingMethods{
|
|
id
|
|
name
|
|
}
|
|
paymentStatus
|
|
totalBalance{
|
|
amount
|
|
}
|
|
}
|
|
}
|
|
}`;
|
|
return cy
|
|
.sendRequestWithQuery(mutation)
|
|
.its("body.data.draftOrderCreate.order");
|
|
}
|
|
|
|
export function completeOrder(orderId) {
|
|
const mutation = `mutation{
|
|
draftOrderComplete(id:"${orderId}"){
|
|
order{
|
|
id
|
|
number
|
|
lines{
|
|
id
|
|
}
|
|
total{
|
|
gross{
|
|
amount
|
|
currency
|
|
}
|
|
}
|
|
}
|
|
errors{
|
|
message
|
|
field
|
|
}
|
|
}
|
|
}`;
|
|
return cy.sendRequestWithQuery(mutation).its("body.data.draftOrderComplete");
|
|
}
|
|
|
|
export function getOrder(orderId) {
|
|
const query = `query getOrder{
|
|
order(id:"${orderId}"){
|
|
status
|
|
token
|
|
paymentStatus
|
|
isShippingRequired
|
|
transactions{
|
|
id
|
|
}
|
|
shippingMethod{
|
|
id
|
|
}
|
|
metadata{
|
|
key
|
|
value
|
|
}
|
|
privateMetadata{
|
|
key
|
|
value
|
|
}
|
|
shippingAddress{
|
|
companyName
|
|
streetAddress1
|
|
streetAddress2
|
|
city
|
|
postalCode
|
|
countryArea
|
|
phone
|
|
}
|
|
billingAddress{
|
|
companyName
|
|
streetAddress1
|
|
streetAddress2
|
|
city
|
|
postalCode
|
|
countryArea
|
|
phone
|
|
}
|
|
}
|
|
}`;
|
|
return cy.sendRequestWithQuery(query).its("body.data.order");
|
|
}
|
|
|
|
export function fulfillOrder({ orderId, warehouse, quantity, linesId }) {
|
|
const lines = linesId.reduce((lines, lineId) => {
|
|
const line = `{orderLineId:"${lineId.id}"
|
|
stocks:{
|
|
quantity:${quantity}
|
|
warehouse:"${warehouse}"
|
|
}
|
|
}`;
|
|
return lines + line;
|
|
}, "");
|
|
const mutation = `mutation fulfill{
|
|
orderFulfill(order:"${orderId}" input:{
|
|
lines:[${lines}]
|
|
}){
|
|
errors{
|
|
field
|
|
message
|
|
}
|
|
order{
|
|
id
|
|
number
|
|
}
|
|
}
|
|
}`;
|
|
return cy.sendRequestWithQuery(mutation).its("body.data.orderFulfill");
|
|
}
|
|
|
|
export function addShippingMethod(orderId, shippingMethodId) {
|
|
const mutation = `mutation{
|
|
orderUpdateShipping(order:"${orderId}", input:{
|
|
shippingMethod:"${shippingMethodId}"
|
|
}){
|
|
order{
|
|
id
|
|
}
|
|
errors{
|
|
field
|
|
message
|
|
}
|
|
}
|
|
}`;
|
|
return cy.sendRequestWithQuery(mutation).its("body.data.orderUpdateShipping");
|
|
}
|