From cf640f79dccde1f2ff6eb8e410d19f234c6404c5 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Thu, 23 May 2024 15:00:27 +0200 Subject: [PATCH] Add tests --- tests/e2e/spec.cy.js | 13 ++++++++++ tests/fixtures/products_3011360030498.json | 28 ++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 tests/fixtures/products_3011360030498.json diff --git a/tests/e2e/spec.cy.js b/tests/e2e/spec.cy.js index 6213b19439e..37c916dada8 100644 --- a/tests/e2e/spec.cy.js +++ b/tests/e2e/spec.cy.js @@ -1,10 +1,12 @@ describe('Basic tests', () => { beforeEach(() => { cy.intercept('GET', 'http://127.0.0.1:8000/api/v1/products?page=1&size=10&order_by=-price_count', { fixture: 'products.json' }) + cy.intercept('GET', 'http://127.0.0.1:8000/api/v1//products?page=1&size=10&code=3011360030498', { fixture: 'products_3011360030498.json' }) cy.intercept('GET', 'http://127.0.0.1:8000/api/v1/products/code/3011360030498', { fixture: 'product_3011360030498.json' }) cy.intercept('GET', 'http://127.0.0.1:8000/api/v1/products/code/0000000000000', { statusCode: 404, body: { "detail": "Product with code 35647000112700 not found" }}) cy.intercept('GET', 'http://127.0.0.1:8000/api/v1/prices?page=1&size=1&order_by=-created*', { fixture: 'prices.json' }) cy.intercept('GET', 'http://127.0.0.1:8000/api/v1/prices?page=1&size=10&order_by=-created', { fixture: 'prices.json' }) + cy.intercept('GET', 'http://127.0.0.1:8000/api/v1/prices?page=1&size=1&order_by=-date&product_code=3011360030498', { fixture: 'product_3011360030498_prices.json' }) cy.intercept('GET', 'http://127.0.0.1:8000/api/v1/prices?page=1&size=10&order_by=-date&product_code=3011360030498', { fixture: 'product_3011360030498_prices.json' }) cy.intercept('GET', 'http://127.0.0.1:8000/api/v1/prices?page=1&size=10&order_by=-date&category_tag=en%3Apitted-apricot', { fixture: 'pitted_apricot_prices.json' }) cy.intercept('GET', 'http://127.0.0.1:8000/api/v1/prices?page=1&size=10&order_by=-date&category_tag=en%3Aaaaaaaaaaaaa', { body: {"items":[],"total":0,"page":1,"size":10,"pages":0} }) @@ -81,4 +83,15 @@ describe('Basic tests', () => { cy.get('[data-name="price-card"]').should('have.length', 0) cy.contains('Load more').should('not.exist') }) + + it('displays the search page', () => { + cy.visit('/search?q=3011360030498') + cy.contains('Welcome to Open Prices!').should('not.exist') + cy.get('#product-title').contains('Mayonnaise Classique') + cy.get('#price-count').contains('1') + cy.contains('Latest price') + cy.get('[data-name="product-missing-chip"]').should('have.length', 0) + cy.get('[data-name="price-card"]').should('have.length', 0) + cy.contains('Load more').should('not.exist') + }) }) diff --git a/tests/fixtures/products_3011360030498.json b/tests/fixtures/products_3011360030498.json new file mode 100644 index 00000000000..56431b22186 --- /dev/null +++ b/tests/fixtures/products_3011360030498.json @@ -0,0 +1,28 @@ +{ + "items": [ + { + "code": "3011360030498", + "price_count": 1, + "id": 368, + "source": "off", + "product_name": "Mayonnaise Classique", + "product_quantity": 175, + "product_quantity_unit": null, + "categories_tags": [], + "brands": "Lesieur", + "brands_tags": [], + "labels_tags": [], + "image_url": "https://images.openfoodfacts.net/images/products/301/136/003/0498/front_en.119.400.jpg", + "nutriscore_grade": null, + "ecoscore_grade": null, + "nova_group": null, + "unique_scans_n": 78, + "created": "2024-02-18T19:39:38.162303+01:00", + "updated": "2024-02-18T19:39:38.186691+01:00" + } + ], + "total": 1, + "page": 1, + "size": 10, + "pages": 1 +}