Skip to content

Commit 40fb961

Browse files
authored
Merge pull request #7222 from usu/feat/cache-checklists
feat: enable caching for for camps/{campId}/checklists
2 parents ed68219 + a5f1b49 commit 40fb961

File tree

4 files changed

+123
-1
lines changed

4 files changed

+123
-1
lines changed

api/config/packages/http_cache.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
app.httpCache.matchPath: '^/?($|index.jsonhal$|content_types|camps/[0-9a-f]*/categories|periods/[0-9a-f]*/schedule_entries|camps/[0-9a-f]*/activities)'
2+
app.httpCache.matchPath: '^/?($|index.jsonhal$|content_types|camps/[0-9a-f]*/categories|periods/[0-9a-f]*/schedule_entries|camps/[0-9a-f]*/activities|camps/[0-9a-f]*/checklists)'
33

44
fos_http_cache:
55
debug:

e2e/specs/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export const cachedEndpoint = Cypress.env('API_ROOT_URL_CACHED')
33
export const grgrCampId = '3c79b99ab424'
44
export const loremIpsumCampId = '9c2447aefe38'
55
export const skilagerCampId = '70ca971c992f'
6+
export const basiskursCampId = '5d28f99890bc'
67

78
export const skilagerPeriodId = '7fa4564a5d5d'
89
export const grgrPeriodId = '76be24bce434'
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
})
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"_links": {
3+
"self": {
4+
"href": "/api/camps/5d28f99890bc/checklists.jsonhal"
5+
},
6+
"items": [
7+
{
8+
"href": "/api/checklists/ebbd0c61eb85"
9+
}
10+
]
11+
},
12+
"totalItems": 1,
13+
"_embedded": {
14+
"items": [
15+
{
16+
"_links": {
17+
"self": {
18+
"href": "/api/checklists/ebbd0c61eb85"
19+
},
20+
"camp": {
21+
"href": "/api/camps/5d28f99890bc"
22+
},
23+
"checklistItems": {
24+
"href": "/api/checklists/ebbd0c61eb85/checklist_items"
25+
}
26+
},
27+
"name": "Ausbildungsziele",
28+
"isPrototype": false,
29+
"id": "ebbd0c61eb85"
30+
}
31+
]
32+
}
33+
}

0 commit comments

Comments
 (0)