@blaze-cms/nextjs-tools 0.124.0-alpha.16 → 0.124.0-alpha.19

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.
@@ -0,0 +1,19 @@
1
+ const {
2
+ checkUrlQuery,
3
+ getPageQuery,
4
+ GET_ENTITY_SCHEMA
5
+ } = require('../../../../../src/application/query');
6
+
7
+ describe('Application query', () => {
8
+ it('should get check url query', () => {
9
+ expect(checkUrlQuery).toMatchSnapshot();
10
+ });
11
+
12
+ it('should get page query', () => {
13
+ expect(getPageQuery({})).toMatchSnapshot();
14
+ });
15
+
16
+ it('should match get entity schema', () => {
17
+ expect(GET_ENTITY_SCHEMA).toMatchSnapshot();
18
+ });
19
+ });
@@ -74,6 +74,8 @@ describe('Check url', () => {
74
74
  const envs = {
75
75
  BLAZE_ROOT_SELECTOR_CLASSES_LIMIT: rootSelectorEnvValue
76
76
  };
77
+ const mockHandlerResponse = () => jest.fn(() => true);
78
+ const cacheControlHeader = 'Cache-Control';
77
79
 
78
80
  beforeAll(() => {
79
81
  setEnvs(envs);
@@ -105,7 +107,7 @@ describe('Check url', () => {
105
107
  });
106
108
 
107
109
  it('should handle static route', async () => {
108
- handleStaticRoutes.getHandler.mockImplementationOnce(() => jest.fn(() => true));
110
+ handleStaticRoutes.getHandler.mockImplementationOnce(mockHandlerResponse);
109
111
  const result = await checkUrl({ ...props, asPath: ROUTE_PATTERN_SITEMAP });
110
112
  expect(handleStaticRoutes.getHandler).toHaveBeenCalledWith(ROUTE_PATTERN_SITEMAP);
111
113
  expect(result).toEqual(true);
@@ -117,18 +119,20 @@ describe('Check url', () => {
117
119
  });
118
120
 
119
121
  it('should set empty Cache-Control header', async () => {
122
+ handleStaticRoutes.getHandler.mockImplementationOnce(mockHandlerResponse);
120
123
  await checkUrl(props);
121
- expect(res.setHeader).toHaveBeenCalledWith('Cache-Control', '');
124
+ expect(res.setHeader).toHaveBeenCalledWith(cacheControlHeader, '');
122
125
  });
123
126
 
124
127
  it('should set Cache-Control header from env', async () => {
128
+ handleStaticRoutes.getHandler.mockImplementationOnce(mockHandlerResponse);
125
129
  const cacheEnvs = {
126
130
  BLAZE_CACHE_CONTROL_HEADER: 'max-age=0'
127
131
  };
128
132
  setEnvs(cacheEnvs);
129
133
  await checkUrl(props);
130
134
  expect(res.setHeader).toHaveBeenCalledWith(
131
- 'Cache-Control',
135
+ cacheControlHeader,
132
136
  cacheEnvs.BLAZE_CACHE_CONTROL_HEADER
133
137
  );
134
138
  deleteEnvs(cacheEnvs);
@@ -205,6 +209,31 @@ describe('Check url', () => {
205
209
  expect(blazeApp.events.emit).toHaveBeenCalled();
206
210
  apolloQueryCheck(apolloClient, rootPage);
207
211
  });
212
+
213
+ it('should set max age in cache control header from entity', async () => {
214
+ const cacheControlMaxAge = 1000;
215
+ apolloClient.query.mockImplementationOnce(async () => ({
216
+ data: {
217
+ checkUrl: { urlTo, pageData: { cacheControlMaxAge } }
218
+ }
219
+ }));
220
+ await checkUrl(props);
221
+ expect(res.setHeader).toHaveBeenCalledWith(cacheControlHeader, `max-age=${cacheControlMaxAge}`);
222
+ });
223
+
224
+ it('should not set cache control header if cacheControlMaxAge=null', async () => {
225
+ const cacheControlMaxAge = null;
226
+ apolloClient.query.mockImplementationOnce(async () => ({
227
+ data: {
228
+ checkUrl: { urlTo, pageData: { cacheControlMaxAge } }
229
+ }
230
+ }));
231
+ await checkUrl(props);
232
+ expect(res.setHeader).not.toHaveBeenCalledWith(
233
+ cacheControlHeader,
234
+ `max-age=${cacheControlMaxAge}`
235
+ );
236
+ });
208
237
  });
209
238
 
210
239
  function apolloQueryCheck(apolloClient, asPath) {