diff --git a/test/edgeworkers/Acrobat_DC_web_prod/main.jest.js b/test/edgeworkers/Acrobat_DC_web_prod/main.jest.js index e2744765..cea1c0be 100644 --- a/test/edgeworkers/Acrobat_DC_web_prod/main.jest.js +++ b/test/edgeworkers/Acrobat_DC_web_prod/main.jest.js @@ -1,6 +1,7 @@ import Request from "request"; import { responseProvider as replaceResponseProvider } from "../../../edgeworkers/Acrobat_DC_web_prod/main.js"; +import { onClientRequest } from "../../../edgeworkers/Acrobat_DC_web_prod/main.js"; import { createResponse } from "create-response"; import { httpRequest } from "http-request"; import { HttpResponsePdf } from "response-pdf"; @@ -64,11 +65,12 @@ describe("EdgeWorker that consumes an HTML document and rewrites it", () => { expect(response.headers).not.toHaveProperty('vary'); expect(fetches).toEqual([ 'https://www.adobe.com/acrobat/online/pdf-to-ppt.html', + 'https://www.adobe.com/dc/dc-generate-cache/dc-hosted-1.0/pdf-to-ppt-en-us.html', 'https://www.adobe.com/acrobat/scripts/scripts.js', 'https://www.adobe.com/acrobat/blocks/dc-converter-widget/dc-converter-widget.js', 'https://www.adobe.com/acrobat/styles/styles.css', - 'https://www.adobe.com/libs/styles/styles.css', - 'https://www.adobe.com/dc/dc-generate-cache/dc-hosted-1.0/pdf-to-ppt-en-us.html']); + 'https://www.adobe.com/libs/styles/styles.css', + ]); }); }); @@ -81,14 +83,34 @@ describe("EdgeWorker that consumes an HTML document and rewrites it", () => { expect(response.headers['header-to-keep']).toEqual('keep'); expect(fetches).toEqual([ 'https://www.adobe.com/jp/acrobat/online/pdf-to-ppt.html', + 'https://www.adobe.com/dc/dc-generate-cache/dc-hosted-1.0/pdf-to-ppt-ja-jp.html', 'https://www.adobe.com/acrobat/scripts/scripts.js', 'https://www.adobe.com/acrobat/blocks/dc-converter-widget/dc-converter-widget.js', 'https://www.adobe.com/acrobat/styles/styles.css', 'https://www.adobe.com/libs/styles/styles.css', - 'https://www.adobe.com/dc/dc-generate-cache/dc-hosted-1.0/pdf-to-ppt-ja-jp.html']); + ]); }); }); + it("responseProvider Mobile", async () => { + let requestMock = new Request({path: '/acrobat/online/pdf-to-ppt', device: 'Mobile'}); + + const responsePromise = replaceResponseProvider(requestMock); + responsePromise.then(response => { + expect(response.status).toEqual(200); + expect(response.headers['header-to-keep']).toEqual('keep'); + expect(response.headers).not.toHaveProperty('accept-encoding'); + expect(response.headers).not.toHaveProperty('vary'); + expect(fetches).toEqual([ + 'https://www.adobe.com/acrobat/online/pdf-to-ppt.html', + 'https://www.adobe.com/acrobat/scripts/scripts.js', + 'https://www.adobe.com/acrobat/blocks/dc-converter-widget/dc-converter-widget.js', + 'https://www.adobe.com/acrobat/styles/styles.css', + 'https://www.adobe.com/libs/styles/styles.css', + ]); + }); + }); + it("404 exception", async () => { let requestMock = new Request({path: '/404/online/pdf-to-ppt'}); @@ -122,5 +144,23 @@ describe("EdgeWorker that consumes an HTML document and rewrites it", () => { expect(response.status).toEqual(500); expect(response.body).toContain('Missing metadata'); }); - }); + }); + + it("onClientReqest", async () => { + let requestMock = new Request({path: '/acrobat/online/pdf-to-ppt'}); + + onClientRequest(requestMock); + expect(requestMock.setVariable).toBeCalledWith('PMUSER_DEVICETYPE', 'Desktop'); + expect(requestMock.cacheKey.includeVariable).toBeCalledWith('PMUSER_DEVICETYPE'); + + requestMock = new Request({path: '/acrobat/online/pdf-to-ppt', device: 'Mobile'}); + + onClientRequest(requestMock); + expect(requestMock.setVariable).toBeCalledWith('PMUSER_DEVICETYPE', 'Mobile'); + + requestMock = new Request({path: '/acrobat/online/pdf-to-ppt', device: 'Tablet'}); + + onClientRequest(requestMock); + expect(requestMock.setVariable).toBeCalledWith('PMUSER_DEVICETYPE', 'Tablet'); + }); }); diff --git a/test/edgeworkers/__mocks__/device.js b/test/edgeworkers/__mocks__/device.js index 7b90d571..1eb7f68a 100644 --- a/test/edgeworkers/__mocks__/device.js +++ b/test/edgeworkers/__mocks__/device.js @@ -1,10 +1,10 @@ -const Device = jest.fn().mockImplementation(() => { +const Device = jest.fn().mockImplementation((device) => { return { brandName:"Chrome", modelName:"90", marketingName:"Chrome 90", isWireless:false, - isTablet:false, + isTablet: device === 'Tablet', os:"Mac OS X", osVersion:"10.15", mobileBrowser:"Chrome", @@ -18,7 +18,7 @@ const Device = jest.fn().mockImplementation(() => { hasFlashSupport:false, acceptsThirdPartyCookie:true, xhtmlSupportLevel:4, - isMobile:false + isMobile: device === 'Mobile' }; }); diff --git a/test/edgeworkers/__mocks__/request.js b/test/edgeworkers/__mocks__/request.js index 9932b8ab..56d587c0 100644 --- a/test/edgeworkers/__mocks__/request.js +++ b/test/edgeworkers/__mocks__/request.js @@ -17,7 +17,7 @@ export const mockJson = jest.fn(); export const mockText = jest.fn(); export const mockArrayBuffer = jest.fn(); -const Request = jest.fn().mockImplementation(({path}) => { +const Request = jest.fn().mockImplementation(({path, device}) => { return { host: "www.adobe.com", method: "GET", @@ -26,7 +26,7 @@ const Request = jest.fn().mockImplementation(({path}) => { query: "param1=value1¶m2=value2", url: `${path}?param1=value1¶m2=value2`, userLocation: new UserLocation(), - device: new Device(), + device: new Device(device), cpCode: 1191398, cacheKey: new CacheKey(), respondWith: mockRespondWith,