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 }) {
|
export function createCategory({ name, slug = name, parent }) {
|
||||||
const parentLine = getValueWithDefault(parent, `parent:"${parent}"`);
|
const parentLine = getValueWithDefault(parent, `parent:"${parent}"`);
|
||||||
|
@ -92,12 +95,13 @@ export function updateCategoryTranslation({
|
||||||
name,
|
name,
|
||||||
description
|
description
|
||||||
}) {
|
}) {
|
||||||
const mutation = `mutation Update_fields{
|
const descriptionData = getDataForDescriptionInVariables(description);
|
||||||
|
const mutation = `mutation Update_fields${descriptionData.mutationVariables}{
|
||||||
categoryTranslate (id:"${categoryTranslateId}",languageCode:${languageCode},input:{
|
categoryTranslate (id:"${categoryTranslateId}",languageCode:${languageCode},input:{
|
||||||
seoTitle:"${seoTitle}",
|
seoTitle:"${seoTitle}",
|
||||||
seoDescription:"${seoDescription}",
|
seoDescription:"${seoDescription}",
|
||||||
name:"${name}"
|
name:"${name}"
|
||||||
description: "{\\"time\\":1642670800306,\\"blocks\\":[{\\"id\\":\\"l8oQJqyxa3\\",\\"type\\":\\"paragraph\\",\\"data\\":{\\"text\\":\\"${description}\\"}}],\\"version\\":\\"2.22.2\\"}"
|
${descriptionData.descriptionLine}
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
errors{
|
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 { stringify } from "../.././formatData/formatJson";
|
||||||
import { returnValueDependsOnShopVersion } from "../../formatData/dataDependingOnVersion";
|
import { returnValueDependsOnShopVersion } from "../../formatData/dataDependingOnVersion";
|
||||||
import { getValueWithDefault, getVariantsListIds } from "./utils/Utils";
|
import {
|
||||||
|
getDataForDescriptionInVariables,
|
||||||
|
getValueWithDefault,
|
||||||
|
getVariantsListIds
|
||||||
|
} from "./utils/Utils";
|
||||||
|
|
||||||
export function getFirstProducts(first, search) {
|
export function getFirstProducts(first, search) {
|
||||||
const filter = search
|
const filter = search
|
||||||
|
@ -102,10 +106,7 @@ export function createProduct({
|
||||||
`collections:["${collectionId}"]`
|
`collections:["${collectionId}"]`
|
||||||
);
|
);
|
||||||
const category = getValueWithDefault(categoryId, `category:"${categoryId}"`);
|
const category = getValueWithDefault(categoryId, `category:"${categoryId}"`);
|
||||||
const descriptionLine = getValueWithDefault(
|
const descriptionData = getDataForDescriptionInVariables(description);
|
||||||
description,
|
|
||||||
`description:"{\\"blocks\\":[{\\"type\\":\\"paragraph\\",\\"data\\":{\\"text\\":\\"${description}\\"}}]}"`
|
|
||||||
);
|
|
||||||
const attributeValuesLine = getValueWithDefault(
|
const attributeValuesLine = getValueWithDefault(
|
||||||
attributeValue,
|
attributeValue,
|
||||||
`values:["${attributeValue}"]`
|
`values:["${attributeValue}"]`
|
||||||
|
@ -117,7 +118,7 @@ export function createProduct({
|
||||||
${attributeValuesLine}
|
${attributeValuesLine}
|
||||||
}]`
|
}]`
|
||||||
);
|
);
|
||||||
const mutation = `mutation{
|
const mutation = `mutation createProduct${descriptionData.mutationVariables}{
|
||||||
productCreate(input:{
|
productCreate(input:{
|
||||||
${attributes}
|
${attributes}
|
||||||
name:"${name}"
|
name:"${name}"
|
||||||
|
@ -126,7 +127,7 @@ export function createProduct({
|
||||||
productType:"${productTypeId}"
|
productType:"${productTypeId}"
|
||||||
${category}
|
${category}
|
||||||
${collection}
|
${collection}
|
||||||
${descriptionLine}
|
${descriptionData.descriptionLine}
|
||||||
}){
|
}){
|
||||||
product{
|
product{
|
||||||
id
|
id
|
||||||
|
@ -139,7 +140,7 @@ export function createProduct({
|
||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
return cy
|
return cy
|
||||||
.sendRequestWithQuery(mutation)
|
.sendRequestWithQuery(mutation, "auth", descriptionData.variables, true)
|
||||||
.its("body.data.productCreate.product");
|
.its("body.data.productCreate.product");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,3 +58,19 @@ export const getPaymentDataLine = paymentData =>
|
||||||
|
|
||||||
export const getValuesInArray = array =>
|
export const getValuesInArray = array =>
|
||||||
getValueWithDefault(array.length === 1, `["${array}"]`, `${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") =>
|
Cypress.Commands.add(
|
||||||
cy.request({
|
"sendRequestWithQuery",
|
||||||
body: {
|
(query, authorization = "auth", variables = "") =>
|
||||||
|
cy.request({
|
||||||
|
body: {
|
||||||
|
variables,
|
||||||
|
query
|
||||||
|
},
|
||||||
|
headers: {
|
||||||
|
Authorization: `JWT ${window.sessionStorage.getItem(authorization)}`
|
||||||
|
},
|
||||||
method: "POST",
|
method: "POST",
|
||||||
query,
|
|
||||||
url: urlList.apiUri
|
url: urlList.apiUri
|
||||||
},
|
})
|
||||||
headers: {
|
|
||||||
Authorization: `JWT ${window.sessionStorage.getItem(authorization)}`
|
|
||||||
},
|
|
||||||
method: "POST",
|
|
||||||
url: urlList.apiUri
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
Cypress.on(
|
Cypress.on(
|
||||||
"uncaught:exception",
|
"uncaught:exception",
|
||||||
|
|
Loading…
Reference in a new issue