Fix failing tests due to changes in the description field (#1903)
* fixed test for product * fix passing description in variables * fix tests for translations
This commit is contained in:
parent
4e9c5b8ddd
commit
6f69f8475c
4 changed files with 50 additions and 23 deletions
|
@ -1,4 +1,7 @@
|
|||
import { getValueWithDefault } from "./utils/Utils";
|
||||
import {
|
||||
getDataForDescriptionInVariables,
|
||||
getValueWithDefault
|
||||
} from "./utils/Utils";
|
||||
|
||||
export function createCategory({ name, slug = name, parent }) {
|
||||
const parentLine = getValueWithDefault(parent, `parent:"${parent}"`);
|
||||
|
@ -92,12 +95,13 @@ export function updateCategoryTranslation({
|
|||
name,
|
||||
description
|
||||
}) {
|
||||
const mutation = `mutation Update_fields{
|
||||
const descriptionData = getDataForDescriptionInVariables(description);
|
||||
const mutation = `mutation Update_fields${descriptionData.mutationVariables}{
|
||||
categoryTranslate (id:"${categoryTranslateId}",languageCode:${languageCode},input:{
|
||||
seoTitle:"${seoTitle}",
|
||||
seoDescription:"${seoDescription}",
|
||||
name:"${name}"
|
||||
description: "{\\"time\\":1642670800306,\\"blocks\\":[{\\"id\\":\\"l8oQJqyxa3\\",\\"type\\":\\"paragraph\\",\\"data\\":{\\"text\\":\\"${description}\\"}}],\\"version\\":\\"2.22.2\\"}"
|
||||
${descriptionData.descriptionLine}
|
||||
})
|
||||
{
|
||||
errors{
|
||||
|
@ -107,5 +111,10 @@ export function updateCategoryTranslation({
|
|||
}
|
||||
}
|
||||
`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
return cy.sendRequestWithQuery(
|
||||
mutation,
|
||||
"auth",
|
||||
descriptionData.variables,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
import { stringify } from "../.././formatData/formatJson";
|
||||
import { returnValueDependsOnShopVersion } from "../../formatData/dataDependingOnVersion";
|
||||
import { getValueWithDefault, getVariantsListIds } from "./utils/Utils";
|
||||
import {
|
||||
getDataForDescriptionInVariables,
|
||||
getValueWithDefault,
|
||||
getVariantsListIds
|
||||
} from "./utils/Utils";
|
||||
|
||||
export function getFirstProducts(first, search) {
|
||||
const filter = search
|
||||
|
@ -102,10 +106,7 @@ export function createProduct({
|
|||
`collections:["${collectionId}"]`
|
||||
);
|
||||
const category = getValueWithDefault(categoryId, `category:"${categoryId}"`);
|
||||
const descriptionLine = getValueWithDefault(
|
||||
description,
|
||||
`description:"{\\"blocks\\":[{\\"type\\":\\"paragraph\\",\\"data\\":{\\"text\\":\\"${description}\\"}}]}"`
|
||||
);
|
||||
const descriptionData = getDataForDescriptionInVariables(description);
|
||||
const attributeValuesLine = getValueWithDefault(
|
||||
attributeValue,
|
||||
`values:["${attributeValue}"]`
|
||||
|
@ -117,7 +118,7 @@ export function createProduct({
|
|||
${attributeValuesLine}
|
||||
}]`
|
||||
);
|
||||
const mutation = `mutation{
|
||||
const mutation = `mutation createProduct${descriptionData.mutationVariables}{
|
||||
productCreate(input:{
|
||||
${attributes}
|
||||
name:"${name}"
|
||||
|
@ -126,7 +127,7 @@ export function createProduct({
|
|||
productType:"${productTypeId}"
|
||||
${category}
|
||||
${collection}
|
||||
${descriptionLine}
|
||||
${descriptionData.descriptionLine}
|
||||
}){
|
||||
product{
|
||||
id
|
||||
|
@ -139,7 +140,7 @@ export function createProduct({
|
|||
}
|
||||
}`;
|
||||
return cy
|
||||
.sendRequestWithQuery(mutation)
|
||||
.sendRequestWithQuery(mutation, "auth", descriptionData.variables, true)
|
||||
.its("body.data.productCreate.product");
|
||||
}
|
||||
|
||||
|
|
|
@ -58,3 +58,19 @@ export const getPaymentDataLine = paymentData =>
|
|||
|
||||
export const getValuesInArray = array =>
|
||||
getValueWithDefault(array.length === 1, `["${array}"]`, `${array}`);
|
||||
|
||||
export function getDataForDescriptionInVariables(descriptionJson) {
|
||||
return {
|
||||
variables: getValueWithDefault(descriptionJson, {
|
||||
description: `{\"blocks\":[{\"type\":\"paragraph\",\"data\":{\"text\":\"${descriptionJson}\"}}]}`
|
||||
}),
|
||||
mutationVariables: getValueWithDefault(
|
||||
descriptionJson,
|
||||
`($description: JSONString!)`
|
||||
),
|
||||
descriptionLine: getValueWithDefault(
|
||||
descriptionJson,
|
||||
`description: $description`
|
||||
)
|
||||
};
|
||||
}
|
||||
|
|
|
@ -55,19 +55,20 @@ Cypress.Commands.add("addAliasToGraphRequest", operationName => {
|
|||
});
|
||||
});
|
||||
|
||||
Cypress.Commands.add("sendRequestWithQuery", (query, authorization = "auth") =>
|
||||
cy.request({
|
||||
body: {
|
||||
Cypress.Commands.add(
|
||||
"sendRequestWithQuery",
|
||||
(query, authorization = "auth", variables = "") =>
|
||||
cy.request({
|
||||
body: {
|
||||
variables,
|
||||
query
|
||||
},
|
||||
headers: {
|
||||
Authorization: `JWT ${window.sessionStorage.getItem(authorization)}`
|
||||
},
|
||||
method: "POST",
|
||||
query,
|
||||
url: urlList.apiUri
|
||||
},
|
||||
headers: {
|
||||
Authorization: `JWT ${window.sessionStorage.getItem(authorization)}`
|
||||
},
|
||||
method: "POST",
|
||||
url: urlList.apiUri
|
||||
})
|
||||
})
|
||||
);
|
||||
Cypress.on(
|
||||
"uncaught:exception",
|
||||
|
|
Loading…
Reference in a new issue