-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dopecodez
committed
Aug 20, 2021
1 parent
22f5530
commit cdbb132
Showing
5 changed files
with
94 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
node_modules | ||
dist | ||
coverage | ||
test.js | ||
test.js | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import * as request from '../source/request'; | ||
import wiki from "../source/index"; | ||
import { htmlString, notFoundJson } from './samples'; | ||
import { pdfError } from '../source/errors'; | ||
import Page, { pdf } from '../source/page'; | ||
import { pageJson } from './samples'; | ||
import * as utils from '../source/utils' | ||
const requestMock = jest.spyOn(request, "returnRestUrl"); | ||
const setTitleMock = jest.spyOn(utils, "setTitleForPage"); | ||
|
||
const pdfResult = "link/pdf" | ||
|
||
afterAll(() => { | ||
requestMock.mockRestore(); | ||
setTitleMock.mockRestore(); | ||
}); | ||
|
||
test('returns link of pdf on page', async () => { | ||
requestMock.mockImplementation(() => { return pdfResult }); | ||
const page = new Page(pageJson); | ||
const result = await page.pdf(); | ||
expect(requestMock).toHaveBeenCalledTimes(1); | ||
expect(result).toStrictEqual(pdfResult); | ||
}); | ||
|
||
test('throws pdf error on page', async () => { | ||
requestMock.mockImplementation(() => { throw Error("this is an error") }); | ||
const page = new Page(pageJson); | ||
const t = async () => { | ||
await page.pdf(); | ||
}; | ||
expect(t).rejects.toThrowError(pdfError); | ||
}); | ||
|
||
test('Throws pdf error', async () => { | ||
requestMock.mockImplementation(() => { throw new Error("This is an error") }); | ||
const t = async () => { | ||
await pdf("Test") | ||
}; | ||
expect(t).rejects.toThrowError(pdfError); | ||
}); | ||
|
||
test('Returns link of pdf', async () => { | ||
requestMock.mockImplementation(() => { return pdfResult }); | ||
const result = await pdf("Test"); | ||
expect(result).toStrictEqual(pdfResult); | ||
}); | ||
|
||
test('Returns link of pdf directly', async () => { | ||
requestMock.mockImplementation(() => { return pdfResult }); | ||
const result = await wiki.pdf("ACID"); | ||
expect(result).toStrictEqual(pdfResult); | ||
}); | ||
|
||
test('throws pdf error directly', async () => { | ||
requestMock.mockImplementation(() => { throw new Error("This is an error") }); | ||
const t = async () => { | ||
await wiki.pdf("ACID"); | ||
}; | ||
expect(t).rejects.toThrowError(pdfError); | ||
}); | ||
|
||
test('Returns link of pdf directly', async () => { | ||
let pdfResultWithAllFormats = pdfResult + '/legal/mobile'; | ||
requestMock.mockImplementation(() => { return pdfResultWithAllFormats }); | ||
const result = await wiki.pdf("ACID", { autoSuggest: true, type: 'mobile', format: 'legal' }); | ||
expect(result).toStrictEqual(pdfResultWithAllFormats); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters