Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed May 23, 2024
1 parent edcdf3a commit cf640f7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/e2e/spec.cy.js
Original file line number Diff line number Diff line change
@@ -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} })
Expand Down Expand Up @@ -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')
})
})
28 changes: 28 additions & 0 deletions tests/fixtures/products_3011360030498.json
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit cf640f7

Please sign in to comment.