|
| 1 | +import { bipiUser, cachedEndpoint, castorUser, basiskursCampId } from '../constants' |
| 2 | +import collectionResponse from './responses/checklists_collection.json' |
| 3 | + |
| 4 | +const collectionXKeys = |
| 5 | + /* campCollaboration for bipiUser */ |
| 6 | + '146c0608237f ' + |
| 7 | + /* checklist entry */ |
| 8 | + 'ebbd0c61eb85 ebbd0c61eb85#camp ' + |
| 9 | + /* collection URI (for detecting addition of new checklists) */ |
| 10 | + '/api/camps/5d28f99890bc/checklists' |
| 11 | + |
| 12 | +describe('cache test: /camps/checklists', () => { |
| 13 | + it('caches /camp/{campId}/checklists separately for each login', () => { |
| 14 | + const uri = `/api/camps/${basiskursCampId}/checklists` |
| 15 | + |
| 16 | + Cypress.session.clearAllSavedSessions() |
| 17 | + cy.login(bipiUser) |
| 18 | + |
| 19 | + // first request is a cache miss |
| 20 | + cy.request(`${cachedEndpoint}${uri}.jsonhal`).then((response) => { |
| 21 | + const headers = response.headers |
| 22 | + expect(headers.xkey).to.eq(collectionXKeys) |
| 23 | + expect(headers['x-cache']).to.eq('MISS') |
| 24 | + expect(response.body).to.deep.equal(collectionResponse) |
| 25 | + }) |
| 26 | + |
| 27 | + // second request is a cache hit |
| 28 | + cy.expectCacheHit(uri) |
| 29 | + |
| 30 | + // request with a new user is a cache miss |
| 31 | + cy.login(castorUser) |
| 32 | + cy.expectCacheMiss(uri) |
| 33 | + }) |
| 34 | + |
| 35 | + it('invalidates /camp/{campId}/checklists on checklist patch', () => { |
| 36 | + const uri = `/api/camps/${basiskursCampId}/checklists` |
| 37 | + |
| 38 | + // bring data into defined state |
| 39 | + Cypress.session.clearAllSavedSessions() |
| 40 | + cy.login(bipiUser) |
| 41 | + cy.apiPatch('/api/checklists/ebbd0c61eb85', { |
| 42 | + name: 'Training targets', |
| 43 | + }) |
| 44 | + |
| 45 | + // warm up cache |
| 46 | + cy.waitForCacheMiss(uri) |
| 47 | + cy.expectCacheHit(uri) |
| 48 | + |
| 49 | + // touch checklist |
| 50 | + cy.apiPatch('/api/checklists/ebbd0c61eb85', { |
| 51 | + name: 'Ausbildungsziele', |
| 52 | + }) |
| 53 | + |
| 54 | + // ensure cache was invalidated |
| 55 | + cy.waitForCacheMiss(uri) |
| 56 | + cy.expectCacheHit(uri) |
| 57 | + }) |
| 58 | + |
| 59 | + it('invalidates /camp/{campId}/checklists for new checklist', () => { |
| 60 | + const uri = `/api/camps/${basiskursCampId}/checklists` |
| 61 | + |
| 62 | + Cypress.session.clearAllSavedSessions() |
| 63 | + cy.login(bipiUser) |
| 64 | + |
| 65 | + // warm up cache |
| 66 | + cy.expectCacheMiss(uri) |
| 67 | + cy.expectCacheHit(uri) |
| 68 | + |
| 69 | + // add new checklist to camp |
| 70 | + cy.apiPost('/api/checklists', { |
| 71 | + camp: `/api/camps/${basiskursCampId}`, |
| 72 | + name: 'new_checklist', |
| 73 | + }).then((response) => { |
| 74 | + const newChecklistUri = response.body._links.self.href |
| 75 | + |
| 76 | + // ensure cache was invalidated |
| 77 | + cy.waitForCacheMiss(uri) |
| 78 | + cy.expectCacheHit(uri) |
| 79 | + |
| 80 | + // delete newly created contentNode |
| 81 | + cy.apiDelete(newChecklistUri) |
| 82 | + |
| 83 | + // ensure cache was invalidated |
| 84 | + cy.waitForCacheMiss(uri) |
| 85 | + cy.expectCacheHit(uri) |
| 86 | + }) |
| 87 | + }) |
| 88 | +}) |
0 commit comments