Skip to content

Commit

Permalink
use conditional caching directive in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jvanecek committed Apr 18, 2022
1 parent cf38fc7 commit 1a11c60
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
45 changes: 42 additions & 3 deletions source/Stargate-Examples-Tests/PetsRESTfulControllerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ PetsRESTfulControllerTest >> testGetPetSummaryJustCreated [
equals: resourceController petSummaryVersion1dot0dot0MediaType;
assert: response entityTag equals: '"1323cdfb8bb0f9011fbd480c5a87c17d05883214"' asEntityTag.
self assertExpiresHeaderFor: response with: 4 hours.
self assertCachingDirectivesFor: response with: #( 'public' 'no-transform' 'must-revalidate' ).
self assertCachingDirectivesFor: response with: #('public').

self withJsonFromContentsIn: response do: [ :json |
self
Expand All @@ -391,7 +391,7 @@ PetsRESTfulControllerTest >> testGetPets [
assert: response contentType asMediaType
equals: resourceController petSummaryVersion1dot0dot0MediaType.
self assertExpiresHeaderFor: response with: 4 hours.
self assertCachingDirectivesFor: response with: #('public' 'no-transform' 'must-revalidate').
self assertCachingDirectivesFor: response with: #('public').

self
withJsonFromContentsIn: response
Expand Down Expand Up @@ -423,7 +423,7 @@ PetsRESTfulControllerTest >> testGetPetsNotEmpty [
assert: response contentType asMediaType
equals: resourceController petSummaryVersion1dot0dot0MediaType.
self assertExpiresHeaderFor: response with: 4 hours.
self assertCachingDirectivesFor: response with: #('public' 'no-transform' 'must-revalidate').
self assertCachingDirectivesFor: response with: #('public').

self
withJsonFromContentsIn: response
Expand All @@ -441,6 +441,45 @@ PetsRESTfulControllerTest >> testGetPetsNotEmpty [
]
]

{ #category : #'tests - get collection' }
PetsRESTfulControllerTest >> testGetPetsNotEmptyAcceptingCompleteMediaType [

| response |

resourceController
createPetBasedOn: ( self requestToCreatePetFrom: '{"name":"Firulais","type":"dog"}' )
within: self newHttpRequestContext.

self assert: petRepository findAll notEmpty.

response := resourceController
getPetsBasedOn: ( self requestToGetPetsAccepting: resourceController petVersion1dot0dot0MediaType )
within: self newHttpRequestContext.

self
assert: response isSuccess;
assert: response status equals: 200;
assert: response contentType asMediaType
equals: resourceController petVersion1dot0dot0MediaType.
self assertExpiresHeaderFor: response with: 4 hours.
self assertCachingDirectivesFor: response with: #('public' 'no-transform' 'must-revalidate').

self
withJsonFromContentsIn: response
do: [ :json | self assertUrl: json selfLocation equals: 'https://pets.example.com/pets' ];
withJsonFromItemsIn: response
do: [ :items |
self
withTheOnlyOneIn: items
do: [ :dogSummary |
self
assert: dogSummary name equals: 'Firulais';
assertUrl: dogSummary selfLocation equals: 'https://pets.example.com/pets/1';
assert: dogSummary type equals: 'dog'.
]
]
]

{ #category : #'tests - get collection' }
PetsRESTfulControllerTest >> testGetPetsWithPagination [

Expand Down
16 changes: 12 additions & 4 deletions source/Stargate-Examples/PetsRESTfulController.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,18 @@ PetsRESTfulController >> initializeRequestHandler [
];
directCachingWith: [ :caching |
caching
expireIn: 4 hours;
bePublic;
doNotTransform;
mustRevalidate
when: [ :response | response contentType = self petVersion1dot0dot0MediaType ]
apply: [ caching
expireIn: 4 hours;
bePublic;
doNotTransform;
mustRevalidate
];
when: [ :response | response contentType = self petSummaryVersion1dot0dot0MediaType ]
apply: [ caching
expireIn: 4 hours;
bePublic
]
];
build
]
Expand Down

0 comments on commit 1a11c60

Please sign in to comment.