|
1 | 1 | const t = require('../test-lib/test.js'); |
2 | 2 | const assert = require('assert'); |
3 | 3 | const _ = require('lodash'); |
| 4 | +// The REST API etag tests below issue their conditional request via rawGet |
| 5 | +// (raw node:http): the built-in fetch used by apos.http adds Cache-Control: |
| 6 | +// no-cache to any request carrying a conditional header (Fetch standard), which |
| 7 | +// would suppress the asserted 304s. The page-serving etag tests stay on |
| 8 | +// apos.http (those routes set 304 explicitly). |
| 9 | +const { rawGet } = t; |
4 | 10 |
|
5 | 11 | describe('Pages', function() { |
6 | 12 | let apos; |
@@ -1087,11 +1093,8 @@ describe('Pages', function() { |
1087 | 1093 | }; |
1088 | 1094 |
|
1089 | 1095 | const response1 = await apos.http.get(`/api/v1/@apostrophecms/page/${homeId}`, { fullResponse: true }); |
1090 | | - const response2 = await apos.http.get(`/api/v1/@apostrophecms/page/${homeId}`, { |
1091 | | - fullResponse: true, |
1092 | | - headers: { |
1093 | | - 'if-none-match': response1.headers.etag |
1094 | | - } |
| 1096 | + const response2 = await rawGet(apos, `/api/v1/@apostrophecms/page/${homeId}`, { |
| 1097 | + 'if-none-match': response1.headers.etag |
1095 | 1098 | }); |
1096 | 1099 |
|
1097 | 1100 | assert(response1.status === 200); |
@@ -1125,11 +1128,8 @@ describe('Pages', function() { |
1125 | 1128 | // so requesting it again should not return a 304 status code |
1126 | 1129 | const pageUpdateResponse = await apos.doc.update(apos.task.getReq(), pageDoc); |
1127 | 1130 |
|
1128 | | - const response2 = await apos.http.get(`/api/v1/@apostrophecms/page/${homeId}`, { |
1129 | | - fullResponse: true, |
1130 | | - headers: { |
1131 | | - 'if-none-match': response1.headers.etag |
1132 | | - } |
| 1131 | + const response2 = await rawGet(apos, `/api/v1/@apostrophecms/page/${homeId}`, { |
| 1132 | + 'if-none-match': response1.headers.etag |
1133 | 1133 | }); |
1134 | 1134 |
|
1135 | 1135 | const eTag1Parts = response1.headers.etag.split(':'); |
@@ -1165,11 +1165,8 @@ describe('Pages', function() { |
1165 | 1165 | outOfDateETagParts[2] = Number(outOfDateETagParts[2]) - |
1166 | 1166 | (4444 + 1) * 1000; // 1s outdated |
1167 | 1167 |
|
1168 | | - const response2 = await apos.http.get(`/api/v1/@apostrophecms/page/${homeId}`, { |
1169 | | - fullResponse: true, |
1170 | | - headers: { |
1171 | | - 'if-none-match': outOfDateETagParts.join(':') |
1172 | | - } |
| 1168 | + const response2 = await rawGet(apos, `/api/v1/@apostrophecms/page/${homeId}`, { |
| 1169 | + 'if-none-match': outOfDateETagParts.join(':') |
1173 | 1170 | }); |
1174 | 1171 |
|
1175 | 1172 | const eTag1Parts = response1.headers.etag.split(':'); |
|
0 commit comments