apostrophe 3.14.2 → 3.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/test/pieces.js CHANGED
@@ -1280,4 +1280,122 @@ describe('Pieces', function() {
1280
1280
  assert(existingPiece.title === 'new product name');
1281
1281
  assert(existingPiece.color === 'red');
1282
1282
  });
1283
+
1284
+ it('should not set a cache-control value when retrieving pieces, when cache option is not set', async () => {
1285
+ const response1 = await apos.http.get('/api/v1/thing', { fullResponse: true });
1286
+ const response2 = await apos.http.get('/api/v1/thing/testThing:en:published', { fullResponse: true });
1287
+
1288
+ assert(response1.headers['cache-control'] === undefined);
1289
+ assert(response2.headers['cache-control'] === undefined);
1290
+ });
1291
+
1292
+ it('should not set a cache-control value when retrieving pieces, when "api" cache option is not set', async () => {
1293
+ apos.thing.options.cache = {
1294
+ page: {
1295
+ maxAge: 5555
1296
+ }
1297
+ };
1298
+
1299
+ const response1 = await apos.http.get('/api/v1/thing', { fullResponse: true });
1300
+ const response2 = await apos.http.get('/api/v1/thing/testThing:en:published', { fullResponse: true });
1301
+
1302
+ assert(response1.headers['cache-control'] === undefined);
1303
+ assert(response2.headers['cache-control'] === undefined);
1304
+
1305
+ delete apos.thing.options.cache;
1306
+ });
1307
+
1308
+ it('should set a "max-age" cache-control value when retrieving pieces, when "api" cache option is set', async () => {
1309
+ apos.thing.options.cache = {
1310
+ api: {
1311
+ maxAge: 3333
1312
+ }
1313
+ };
1314
+
1315
+ const response1 = await apos.http.get('/api/v1/thing', { fullResponse: true });
1316
+ const response2 = await apos.http.get('/api/v1/thing/testThing:en:published', { fullResponse: true });
1317
+
1318
+ assert(response1.headers['cache-control'] === 'max-age=3333');
1319
+ assert(response2.headers['cache-control'] === 'max-age=3333');
1320
+
1321
+ delete apos.thing.options.cache;
1322
+ });
1323
+
1324
+ it('should set a "no-store" cache-control value when retrieving pieces, when user is connected', async () => {
1325
+ await apos.http.post('/api/v1/@apostrophecms/login/login', {
1326
+ body: {
1327
+ username: 'admin',
1328
+ password: 'admin',
1329
+ session: true
1330
+ },
1331
+ jar
1332
+ });
1333
+
1334
+ const response1 = await apos.http.get('/api/v1/thing', {
1335
+ fullResponse: true,
1336
+ jar
1337
+ });
1338
+ const response2 = await apos.http.get('/api/v1/thing/testThing:en:published', {
1339
+ fullResponse: true,
1340
+ jar
1341
+ });
1342
+
1343
+ assert(response1.headers['cache-control'] === 'no-store');
1344
+ assert(response2.headers['cache-control'] === 'no-store');
1345
+ });
1346
+
1347
+ it('should set a "no-store" cache-control value when retrieving pieces, when "api" cache option is set, when user is connected', async () => {
1348
+ apos.thing.options.cache = {
1349
+ api: {
1350
+ maxAge: 3333
1351
+ }
1352
+ };
1353
+
1354
+ await apos.http.post('/api/v1/@apostrophecms/login/login', {
1355
+ body: {
1356
+ username: 'admin',
1357
+ password: 'admin',
1358
+ session: true
1359
+ },
1360
+ jar
1361
+ });
1362
+
1363
+ const response1 = await apos.http.get('/api/v1/thing', {
1364
+ fullResponse: true,
1365
+ jar
1366
+ });
1367
+ const response2 = await apos.http.get('/api/v1/thing/testThing:en:published', {
1368
+ fullResponse: true,
1369
+ jar
1370
+ });
1371
+
1372
+ assert(response1.headers['cache-control'] === 'no-store');
1373
+ assert(response2.headers['cache-control'] === 'no-store');
1374
+
1375
+ delete apos.thing.options.cache;
1376
+ });
1377
+
1378
+ it('should set a "no-store" cache-control value when retrieving pieces, when user is connected using an api key', async () => {
1379
+ const response1 = await apos.http.get(`/api/v1/thing?apiKey=${apiKey}`, { fullResponse: true });
1380
+ const response2 = await apos.http.get(`/api/v1/thing/testThing:en:published?apiKey=${apiKey}`, { fullResponse: true });
1381
+
1382
+ assert(response1.headers['cache-control'] === 'no-store');
1383
+ assert(response2.headers['cache-control'] === 'no-store');
1384
+ });
1385
+
1386
+ it('should set a "no-store" cache-control value when retrieving pieces, when "api" cache option is set, when user is connected using an api key', async () => {
1387
+ apos.thing.options.cache = {
1388
+ api: {
1389
+ maxAge: 3333
1390
+ }
1391
+ };
1392
+
1393
+ const response1 = await apos.http.get(`/api/v1/thing?apiKey=${apiKey}`, { fullResponse: true });
1394
+ const response2 = await apos.http.get(`/api/v1/thing/testThing:en:published?apiKey=${apiKey}`, { fullResponse: true });
1395
+
1396
+ assert(response1.headers['cache-control'] === 'no-store');
1397
+ assert(response2.headers['cache-control'] === 'no-store');
1398
+
1399
+ delete apos.thing.options.cache;
1400
+ });
1283
1401
  });
package/test/templates.js CHANGED
@@ -115,6 +115,7 @@ describe('Templates', function() {
115
115
  assert($body.length);
116
116
  const aposData = JSON.parse($body.attr('data-apos'));
117
117
  assert(aposData);
118
+ assert(aposData.shortName);
118
119
  assert(aposData.csrfCookieName);
119
120
  assert(!aposData.modules['@apostrophecms/admin-bar']);
120
121
  assert(result.indexOf('<title>I am the title</title>') !== -1);
@@ -129,6 +130,7 @@ describe('Templates', function() {
129
130
  assert($body.length);
130
131
  const aposData = JSON.parse($body.attr('data-apos'));
131
132
  assert(aposData);
133
+ assert(aposData.shortName);
132
134
  assert(aposData.modules['@apostrophecms/admin-bar'].items.length);
133
135
  assert(result.indexOf('<title>I am the title</title>') !== -1);
134
136
  assert(result.indexOf('<h2>I am the main content</h2>') !== -1);