Skip to content

Commit

Permalink
Adapt UI tests to use locale in API tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jolelievre committed Dec 16, 2024
1 parent dbf22a1 commit 4a2b504
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ describe('API : GET /customers/group/{customerGroupId}', async () => {

expect(jsonResponse).to.have.property('localizedNames');
expect(jsonResponse.localizedNames).to.be.a('object');
expect(jsonResponse.localizedNames[dataLanguages.english.id]).to.be.equal(nameEn);
expect(jsonResponse.localizedNames[dataLanguages.french.id]).to.be.equal(nameFr);
expect(jsonResponse.localizedNames[dataLanguages.english.locale]).to.be.equal(nameEn);
expect(jsonResponse.localizedNames[dataLanguages.french.locale]).to.be.equal(nameFr);
});

it('should check the JSON Response : `reductionPercent`', async function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ describe('API : PUT /customers/group/{customerGroupId}', async () => {
data: {
customerGroupId: idCustomerGroup,
localizedNames: {
[dataLanguages.french.id]: updateGroupData.frName,
[dataLanguages.english.id]: updateGroupData.name,
[dataLanguages.french.locale]: updateGroupData.frName,
[dataLanguages.english.locale]: updateGroupData.name,
},
reductionPercent: updateGroupData.discount,
displayPriceTaxExcluded: updateGroupData.priceDisplayMethod === 'Tax excluded',
Expand Down Expand Up @@ -257,7 +257,10 @@ describe('API : PUT /customers/group/{customerGroupId}', async () => {
await testContext.addContextItem(this, 'testIdentifier', 'checkResponseJSON', baseContext);

expect(jsonResponse.customerGroupId).to.equal(idCustomerGroup);
expect(jsonResponse.localizedNames).to.deep.equal({1: updateGroupData.name, 2: updateGroupData.frName});
expect(jsonResponse.localizedNames).to.deep.equal({
[dataLanguages.english.locale]: updateGroupData.name,
[dataLanguages.french.locale]: updateGroupData.frName,
});
expect(jsonResponse.reductionPercent).to.equal(updateGroupData.discount);
expect(jsonResponse.displayPriceTaxExcluded).to.equal(updateGroupData.priceDisplayMethod === 'Tax excluded');
expect(jsonResponse.showPrice).to.equal(updateGroupData.shownPrices);
Expand Down Expand Up @@ -292,14 +295,14 @@ describe('API : PUT /customers/group/{customerGroupId}', async () => {
await testContext.addContextItem(this, 'testIdentifier', 'checkResponseLocalizedNamesEN', baseContext);

const value = await boCustomerGroupsCreatePage.getValue(page, 'localizedNames', dataLanguages.english.id);
expect(jsonResponse.localizedNames[dataLanguages.english.id]).to.be.equal(value);
expect(jsonResponse.localizedNames[dataLanguages.english.locale]).to.be.equal(value);
});

it('should check the JSON Response : `localizedNames` (FR)', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkResponseLocalizedNamesFR', baseContext);

const value = await boCustomerGroupsCreatePage.getValue(page, 'localizedNames', dataLanguages.french.id);
expect(jsonResponse.localizedNames[dataLanguages.french.id]).to.be.equal(value);
expect(jsonResponse.localizedNames[dataLanguages.french.locale]).to.be.equal(value);
});

it('should check the JSON Response : `reductionPercent`', async function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ describe('API : POST /product', async () => {
type: createProduct.type,
active: createProduct.status,
names: {
[dataLanguages.english.id]: createProduct.name,
[dataLanguages.french.id]: createProduct.nameFR,
[dataLanguages.english.locale]: createProduct.name,
[dataLanguages.french.locale]: createProduct.nameFR,
},
descriptions: {
[dataLanguages.english.id]: createProduct.description,
[dataLanguages.french.id]: createProduct.descriptionFR,
[dataLanguages.english.locale]: createProduct.description,
[dataLanguages.french.locale]: createProduct.descriptionFR,
},
},
});
Expand Down Expand Up @@ -183,8 +183,8 @@ describe('API : POST /product', async () => {

expect(jsonResponse.productId).to.be.gt(0);
expect(jsonResponse.type).to.equal(createProduct.type);
expect(jsonResponse.names[dataLanguages.english.id]).to.equal(createProduct.name);
expect(jsonResponse.names[dataLanguages.french.id]).to.equal(createProduct.nameFR);
expect(jsonResponse.names[dataLanguages.english.locale]).to.equal(createProduct.name);
expect(jsonResponse.names[dataLanguages.french.locale]).to.equal(createProduct.nameFR);
// @todo : https://github.com/PrestaShop/PrestaShop/issues/35619
//expect(jsonResponse.descriptions[dataLanguages.english.id]).to.equal(createProduct.description);
//expect(jsonResponse.descriptions[dataLanguages.french.id]).to.equal(createProduct.descriptionFR);
Expand Down Expand Up @@ -246,28 +246,28 @@ describe('API : POST /product', async () => {
await testContext.addContextItem(this, 'testIdentifier', 'checkResponseNamesEN', baseContext);

const value = await createProductsPage.getProductName(page, dataLanguages.english.isoCode);
expect(value).to.equal(jsonResponse.names[dataLanguages.english.id]);
expect(value).to.equal(jsonResponse.names[dataLanguages.english.locale]);
});

it('should check the JSON Response : `names` (FR)', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkResponseNamesFR', baseContext);

const value = await createProductsPage.getProductName(page, dataLanguages.french.isoCode);
expect(value).to.equal(jsonResponse.names[dataLanguages.french.id]);
expect(value).to.equal(jsonResponse.names[dataLanguages.french.locale]);
});

it('should check the JSON Response : `description` (EN)', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkResponseDescriptionsEN', baseContext);

const value = await boProductsCreateTabDescriptionPage.getValue(page, 'description', dataLanguages.english.id.toString());
expect(value).to.equal(jsonResponse.descriptions[dataLanguages.english.id]);
expect(value).to.equal(jsonResponse.descriptions[dataLanguages.english.locale]);
});

it('should check the JSON Response : `description` (FR)', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkResponseDescriptionsFR', baseContext);

const value = await boProductsCreateTabDescriptionPage.getValue(page, 'description', dataLanguages.french.id.toString());
expect(value).to.equal(jsonResponse.descriptions[dataLanguages.french.id]);
expect(value).to.equal(jsonResponse.descriptions[dataLanguages.french.locale]);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,17 @@ describe('API : GET /product/{productId}', async () => {

expect(jsonResponse).to.have.property('names');
expect(jsonResponse.names).to.be.a('object');
expect(jsonResponse.names[dataLanguages.english.id]).to.be.equal(productNameEn);
expect(jsonResponse.names[dataLanguages.french.id]).to.be.equal(productNameFr);
expect(jsonResponse.names[dataLanguages.english.locale]).to.be.equal(productNameEn);
expect(jsonResponse.names[dataLanguages.french.locale]).to.be.equal(productNameFr);
});

it('should check the JSON Response : `descriptions`', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkResponseDescriptions', baseContext);

expect(jsonResponse).to.have.property('descriptions');
expect(jsonResponse.descriptions).to.be.a('object');
expect(jsonResponse.descriptions[dataLanguages.english.id]).to.be.equal(productDescriptionEn);
expect(jsonResponse.descriptions[dataLanguages.french.id]).to.be.equal(productDescriptionFr);
expect(jsonResponse.descriptions[dataLanguages.english.locale]).to.be.equal(productDescriptionEn);
expect(jsonResponse.descriptions[dataLanguages.french.locale]).to.be.equal(productDescriptionFr);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,15 @@ describe('API : PATCH /product/{productId}', async () => {
{
propertyName: 'names',
propertyValue: {
[dataLanguages.english.id]: patchProduct.name,
[dataLanguages.french.id]: patchProduct.nameFR,
[dataLanguages.english.locale]: patchProduct.name,
[dataLanguages.french.locale]: patchProduct.nameFR,
},
},
{
propertyName: 'descriptions',
propertyValue: {
[dataLanguages.english.id]: patchProduct.description,
[dataLanguages.french.id]: patchProduct.descriptionFR,
[dataLanguages.english.locale]: patchProduct.description,
[dataLanguages.french.locale]: patchProduct.descriptionFR,
},
},
].forEach((data: { propertyName: string, propertyValue: boolean|string|object}) => {
Expand Down Expand Up @@ -248,8 +248,8 @@ describe('API : PATCH /product/{productId}', async () => {
const valuePropertyEN = await createProductsPage.getProductName(page, dataLanguages.english.isoCode);
const valuePropertyFR = await createProductsPage.getProductName(page, dataLanguages.french.isoCode);
expect({
[dataLanguages.english.id]: valuePropertyEN,
[dataLanguages.french.id]: valuePropertyFR,
[dataLanguages.english.locale]: valuePropertyEN,
[dataLanguages.french.locale]: valuePropertyFR,
}).to.deep.equal(data.propertyValue);
} else if (data.propertyName === 'descriptions') {
const valuePropertyEN = await boProductsCreateTabDescriptionPage.getValue(
Expand All @@ -263,8 +263,8 @@ describe('API : PATCH /product/{productId}', async () => {
dataLanguages.french.id.toString(),
);
expect({
[dataLanguages.english.id]: valuePropertyEN,
[dataLanguages.french.id]: valuePropertyFR,
[dataLanguages.english.locale]: valuePropertyEN,
[dataLanguages.french.locale]: valuePropertyFR,
}).to.deep.equal(data.propertyValue);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ describe('API : POST /product/{productId}/image', async () => {

expect(jsonResponse.thumbnailUrl).to.be.a('string');

expect(jsonResponse.legends[dataLanguages.english.id]).to.be.a('string');
expect(jsonResponse.legends[dataLanguages.english.id]).to.equals('');
expect(jsonResponse.legends[dataLanguages.french.id]).to.be.a('string');
expect(jsonResponse.legends[dataLanguages.french.id]).to.equals('');
expect(jsonResponse.legends[dataLanguages.english.locale]).to.be.a('string');
expect(jsonResponse.legends[dataLanguages.english.locale]).to.equals('');
expect(jsonResponse.legends[dataLanguages.french.locale]).to.be.a('string');
expect(jsonResponse.legends[dataLanguages.french.locale]).to.equals('');

expect(jsonResponse.cover).to.be.a('boolean');
expect(jsonResponse.cover).to.be.equals(true);
Expand Down Expand Up @@ -262,8 +262,8 @@ describe('API : POST /product/{productId}/image', async () => {
it('should check the JSON Response : `legends`', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkResponseLegends', baseContext);

expect(productImageInformation.caption.en).to.equal(jsonResponse.legends[dataLanguages.english.id]);
expect(productImageInformation.caption.fr).to.equal(jsonResponse.legends[dataLanguages.french.id]);
expect(productImageInformation.caption.en).to.equal(jsonResponse.legends[dataLanguages.english.locale]);
expect(productImageInformation.caption.fr).to.equal(jsonResponse.legends[dataLanguages.french.locale]);
});

it('should check the JSON Response : `cover`', async function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ describe('API : GET /product/{productId}/images', async () => {
expect(jsonResponse[i].imageId).to.be.gt(0);
expect(jsonResponse[i].imageUrl).to.be.a('string');
expect(jsonResponse[i].thumbnailUrl).to.be.a('string');
expect(jsonResponse[i].legends[dataLanguages.english.id]).to.be.a('string');
expect(jsonResponse[i].legends[dataLanguages.french.id]).to.be.a('string');
expect(jsonResponse[i].legends[dataLanguages.english.locale]).to.be.a('string');
expect(jsonResponse[i].legends[dataLanguages.french.locale]).to.be.a('string');
expect(jsonResponse[i].cover).to.be.a('boolean');
expect(jsonResponse[i].position).to.be.a('number');
expect(jsonResponse[i].shopIds).to.be.a('array');
Expand Down Expand Up @@ -226,8 +226,8 @@ describe('API : GET /product/{productId}/images', async () => {

expect(productImageInformation.id).to.equal(jsonResponse[idxItem].imageId);

expect(productImageInformation.caption.en).to.equal(jsonResponse[idxItem].legends[dataLanguages.english.id]);
expect(productImageInformation.caption.fr).to.equal(jsonResponse[idxItem].legends[dataLanguages.french.id]);
expect(productImageInformation.caption.en).to.equal(jsonResponse[idxItem].legends[dataLanguages.english.locale]);
expect(productImageInformation.caption.fr).to.equal(jsonResponse[idxItem].legends[dataLanguages.french.locale]);

expect(productImageInformation.isCover).to.equal(jsonResponse[idxItem].cover);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ describe('API : GET /product/image/{imageId}', async () => {
expect(jsonResponse.imageId).to.be.gt(0);
expect(jsonResponse.imageUrl).to.be.a('string');
expect(jsonResponse.thumbnailUrl).to.be.a('string');
expect(jsonResponse.legends[dataLanguages.english.id]).to.be.a('string');
expect(jsonResponse.legends[dataLanguages.french.id]).to.be.a('string');
expect(jsonResponse.legends[dataLanguages.english.locale]).to.be.a('string');
expect(jsonResponse.legends[dataLanguages.french.locale]).to.be.a('string');
expect(jsonResponse.cover).to.be.a('boolean');
expect(jsonResponse.position).to.be.a('number');
expect(jsonResponse.shopIds).to.be.a('array');
Expand Down Expand Up @@ -218,8 +218,8 @@ describe('API : GET /product/image/{imageId}', async () => {

expect(productImageInformation.id).to.equal(jsonResponse.imageId);

expect(productImageInformation.caption.en).to.equal(jsonResponse.legends[dataLanguages.english.id]);
expect(productImageInformation.caption.fr).to.equal(jsonResponse.legends[dataLanguages.french.id]);
expect(productImageInformation.caption.en).to.equal(jsonResponse.legends[dataLanguages.english.locale]);
expect(productImageInformation.caption.fr).to.equal(jsonResponse.legends[dataLanguages.french.locale]);

expect(productImageInformation.isCover).to.equal(jsonResponse.cover);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ describe('API : POST /product/image/{imageId}', async () => {
await testContext.addContextItem(this, 'testIdentifier', 'requestEndpoint', baseContext);

const dataMultipart: any = {};
dataMultipart[`legends[${dataLanguages.english.id}]`] = productCaptionUpdatedEN;
dataMultipart[`legends[${dataLanguages.french.id}]`] = productCaptionUpdatedFR;
dataMultipart[`legends[${dataLanguages.english.locale}]`] = productCaptionUpdatedEN;
dataMultipart[`legends[${dataLanguages.french.locale}]`] = productCaptionUpdatedFR;

const apiResponse = await apiContext.post(`product/image/${productImageInformation.id}`, {
headers: {
Expand Down Expand Up @@ -281,10 +281,10 @@ describe('API : POST /product/image/{imageId}', async () => {

expect(jsonResponse.thumbnailUrl).to.be.a('string');

expect(jsonResponse.legends[dataLanguages.english.id]).to.be.a('string');
expect(jsonResponse.legends[dataLanguages.english.id]).to.equals(productCaptionUpdatedEN);
expect(jsonResponse.legends[dataLanguages.french.id]).to.be.a('string');
expect(jsonResponse.legends[dataLanguages.french.id]).to.equals(productCaptionUpdatedFR);
expect(jsonResponse.legends[dataLanguages.english.locale]).to.be.a('string');
expect(jsonResponse.legends[dataLanguages.english.locale]).to.equals(productCaptionUpdatedEN);
expect(jsonResponse.legends[dataLanguages.french.locale]).to.be.a('string');
expect(jsonResponse.legends[dataLanguages.french.locale]).to.equals(productCaptionUpdatedFR);

expect(jsonResponse.cover).to.be.a('boolean');
expect(jsonResponse.cover).to.be.equals(true);
Expand Down Expand Up @@ -314,10 +314,10 @@ describe('API : POST /product/image/{imageId}', async () => {
it('should check the JSON Response : `legends`', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkResponseLegends', baseContext);

expect(productImageInformation.caption.en).to.equal(jsonResponse.legends[dataLanguages.english.id]);
expect(productImageInformation.caption.en).to.equal(jsonResponse.legends[dataLanguages.english.locale]);
expect(productImageInformation.caption.en).to.equal(productCaptionUpdatedEN);

expect(productImageInformation.caption.fr).to.equal(jsonResponse.legends[dataLanguages.french.id]);
expect(productImageInformation.caption.fr).to.equal(jsonResponse.legends[dataLanguages.french.locale]);
expect(productImageInformation.caption.fr).to.equal(productCaptionUpdatedFR);
});

Expand Down
4 changes: 2 additions & 2 deletions tests/UI/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4a2b504

Please sign in to comment.