-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Doczilla-APP/improvements
chore: Added testing
- Loading branch information
Showing
14 changed files
with
5,563 additions
and
152 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
dist |
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,94 @@ | ||
{ | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": 2020, | ||
"sourceType": "module" | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"plugins": [ | ||
"@typescript-eslint", | ||
"simple-import-sort" | ||
], | ||
"overrides": [ | ||
{ | ||
"files": [ | ||
"*.ts" | ||
], | ||
"rules": { | ||
"no-unneeded-ternary": [ | ||
"error" | ||
], | ||
"no-nested-ternary": [ | ||
"error" | ||
], | ||
"multiline-ternary": [ | ||
"error", | ||
"always-multiline" | ||
], | ||
"operator-linebreak": [ | ||
"error", | ||
"before" | ||
], | ||
"simple-import-sort/imports": [ | ||
"warn", | ||
{ | ||
"groups": [ | ||
[ | ||
"^@?\\w" | ||
], | ||
// "type" imports. | ||
[ | ||
"^.*\\u0000$" | ||
], | ||
// Absolute imports and other imports such as Vue-style `@/foo`. | ||
// Anything not matched in another group. | ||
[ | ||
"^" | ||
], | ||
// Relative imports. | ||
// Anything that starts with a dot. | ||
[ | ||
"^\\." | ||
] | ||
] | ||
} | ||
], | ||
"simple-import-sort/exports": "warn", | ||
"object-curly-spacing": [ | ||
"error", | ||
"always" | ||
], | ||
"quotes": [ | ||
"warn", | ||
"single" | ||
], | ||
"func-style": [ | ||
"warn", | ||
"declaration" | ||
] | ||
} | ||
}, | ||
{ | ||
"files": [ | ||
"*.spec.ts", | ||
"*.spec.tsx", | ||
"*.spec.js", | ||
"*.spec.jsx" | ||
], | ||
"env": { | ||
"jest": true | ||
}, | ||
"rules": {} | ||
}, | ||
{ | ||
"files": "*.json", | ||
"parser": "jsonc-eslint-parser", | ||
"rules": {} | ||
} | ||
] | ||
} |
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,73 @@ | ||
name: "Check PR" | ||
on: | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Cache node modules | ||
id: cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.cache | ||
**/node_modules | ||
key: cache-node-modules-${{ hashFiles('yarn.lock') }} | ||
restore-keys: | | ||
cache-node-modules- | ||
- name: Set up Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
|
||
- name: yarn install | ||
if: steps.cache.outputs.cache-hit != 'true' | ||
shell: bash | ||
run: yarn install --immutable | ||
|
||
- name: Build | ||
shell: bash | ||
run: yarn build | ||
|
||
test: | ||
name: Test (${{ matrix.node }}) | ||
needs: [build] | ||
strategy: | ||
matrix: | ||
os: | ||
- "ubuntu-latest" | ||
node: | ||
- "20" | ||
- "18" | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup node | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
|
||
- name: Print Node.js version | ||
run: node -v | ||
|
||
- name: Cache node modules | ||
id: cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.cache | ||
**/node_modules | ||
key: cache-node-modules-${{ hashFiles('yarn.lock') }} | ||
restore-keys: | | ||
cache-node-modules- | ||
- name: Test | ||
run: yarn test |
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,5 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node' | ||
} |
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 |
---|---|---|
|
@@ -29,15 +29,30 @@ | |
"module": "./dist/esm/index.js", | ||
"scripts": { | ||
"build": "tsc && tsc -p tsconfig.esm.json", | ||
"generate:sdk": "node ./generate-models.js && yarn build" | ||
"generate:sdk": "node ./generate-models.js && yarn build", | ||
"lint": "eslint --ext .ts .", | ||
"test": "jest" | ||
}, | ||
"dependencies": { | ||
"axios": "^1.6.2" | ||
}, | ||
"devDependencies": { | ||
"@jest/globals": "^29.7.0", | ||
"@types/jest": "^29.5.11", | ||
"@types/node": "^20.10.4", | ||
"@typescript-eslint/eslint-plugin": "^6.15.0", | ||
"@typescript-eslint/parser": "^6.15.0", | ||
"axios-mock-adapter": "^1.22.0", | ||
"eslint": "8.56.0", | ||
"eslint-plugin-import": "2.29.1", | ||
"eslint-plugin-simple-import-sort": "^10.0.0", | ||
"jest": "^29.7.0", | ||
"openapi-typescript-codegen": "^0.25.0", | ||
"ts-jest": "^29.1.1", | ||
"typescript": "^5.3" | ||
}, | ||
"packageManager": "[email protected]" | ||
"packageManager": "[email protected]", | ||
"engines": { | ||
"node": ">=18.*" | ||
} | ||
} |
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,19 @@ | ||
import { describe, expect, test } from '@jest/globals' | ||
|
||
import Doczilla from '../Doczilla' | ||
|
||
describe('Doczilla', () => { | ||
|
||
test('it should throw an error if no api key is provided', () => { | ||
let error: Error | ||
try { | ||
// @ts-expect-error | ||
new Doczilla() | ||
} catch (err) { | ||
error = err | ||
} | ||
|
||
expect(error.message).toEqual('No token provided!') | ||
}) | ||
|
||
}) |
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,29 @@ | ||
import { describe, expect, test } from '@jest/globals' | ||
import MockAdapter from 'axios-mock-adapter' | ||
|
||
import Doczilla from '../Doczilla' | ||
|
||
describe('Page', () => { | ||
|
||
const client = new Doczilla('fake-api-token') | ||
// @ts-expect-error private property | ||
const axiosMock = new MockAdapter(client.client) | ||
|
||
axiosMock.onAny().reply(200, Buffer.from('')) | ||
|
||
test('it encode the page.html option', async () => { | ||
await client.pdf.direct({ | ||
page: { | ||
html: '<div>Your first Doczilla PDF</div>' | ||
} | ||
}) | ||
|
||
expect(axiosMock.history.post.length).toBe(1) | ||
expect(axiosMock.history.post[0].data).toEqual(JSON.stringify({ | ||
page: { | ||
html: 'PGRpdj5Zb3VyIGZpcnN0IERvY3ppbGxhIFBERjwvZGl2Pg==' | ||
} | ||
})) | ||
}) | ||
|
||
}) |
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,37 @@ | ||
import { describe, expect, test } from '@jest/globals' | ||
import MockAdapter from 'axios-mock-adapter' | ||
|
||
import Doczilla from '../Doczilla' | ||
|
||
describe('PDF', () => { | ||
|
||
const client = new Doczilla('fake-api-token') | ||
// @ts-expect-error private property | ||
const axiosMock = new MockAdapter(client.client) | ||
|
||
axiosMock.onAny().reply(200, Buffer.from('')) | ||
|
||
test('it should encode the pdf.headerTemplate and pdf.footerTemplate options', async () => { | ||
await client.pdf.direct({ | ||
page: { | ||
html: '<div>Your first Doczilla PDF</div>' | ||
}, | ||
pdf: { | ||
headerTemplate: '<div>Header template</div>', | ||
footerTemplate: '<div>Footer template</div>' | ||
} | ||
}) | ||
|
||
expect(axiosMock.history.post.length).toBe(1) | ||
expect(axiosMock.history.post[0].data).toEqual(JSON.stringify({ | ||
page: { | ||
html: 'PGRpdj5Zb3VyIGZpcnN0IERvY3ppbGxhIFBERjwvZGl2Pg==' | ||
}, | ||
pdf: { | ||
headerTemplate: 'PGRpdj5IZWFkZXIgdGVtcGxhdGU8L2Rpdj4=', | ||
footerTemplate: 'PGRpdj5Gb290ZXIgdGVtcGxhdGU8L2Rpdj4=' | ||
} | ||
})) | ||
}) | ||
|
||
}) |
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
Oops, something went wrong.