Skip to content

Commit

Permalink
Add teste
Browse files Browse the repository at this point in the history
  • Loading branch information
TsayAdobe committed Sep 5, 2024
1 parent e4a65d2 commit 51bc0ed
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
48 changes: 44 additions & 4 deletions test/edgeworkers/Acrobat_DC_web_prod/main.jest.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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',
]);
});
});

Expand All @@ -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'});

Expand Down Expand Up @@ -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');
});
});
6 changes: 3 additions & 3 deletions test/edgeworkers/__mocks__/device.js
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -18,7 +18,7 @@ const Device = jest.fn().mockImplementation(() => {
hasFlashSupport:false,
acceptsThirdPartyCookie:true,
xhtmlSupportLevel:4,
isMobile:false
isMobile: device === 'Mobile'
};
});

Expand Down
4 changes: 2 additions & 2 deletions test/edgeworkers/__mocks__/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -26,7 +26,7 @@ const Request = jest.fn().mockImplementation(({path}) => {
query: "param1=value1&param2=value2",
url: `${path}?param1=value1&param2=value2`,
userLocation: new UserLocation(),
device: new Device(),
device: new Device(device),
cpCode: 1191398,
cacheKey: new CacheKey(),
respondWith: mockRespondWith,
Expand Down

0 comments on commit 51bc0ed

Please sign in to comment.