-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove faker and add unit tests
* fix: remove faker * chore: add rollup config * test: add unit tests
- Loading branch information
1 parent
c95100f
commit 3079720
Showing
10 changed files
with
1,930 additions
and
61 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 |
---|---|---|
|
@@ -2,4 +2,5 @@ src/ | |
.travis.yml | ||
.releaserc.yml | ||
yarn-error.log | ||
tsconfig.json | ||
tsconfig.json | ||
rollup.config.js |
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,5 +1,5 @@ | ||
language: node_js | ||
node_js: "11" | ||
node_js: "12" | ||
|
||
cache: yarn | ||
|
||
|
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,7 @@ | ||
module.exports = { | ||
roots: ["<rootDir>/src"], | ||
testMatch: ["**/?(*.)+(spec|test).+(ts|tsx|js)"], | ||
transform: { | ||
"^.+\\.(ts|tsx)?$": "ts-jest" | ||
} | ||
}; |
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,30 @@ | ||
const commonjs = require("rollup-plugin-commonjs"); | ||
const typescript = require("rollup-plugin-typescript2"); | ||
const resolve = require("rollup-plugin-node-resolve"); | ||
|
||
module.exports = { | ||
input: "./src/index.ts", | ||
output: { | ||
file: "dist/index.js", | ||
format: "cjs", | ||
exports: "named" | ||
}, | ||
plugins: [ | ||
// @ts-ignore | ||
typescript({ | ||
lib: ["es5", "es6"], | ||
target: "es6", | ||
typescript: require("typescript"), | ||
module: "CommonJS" | ||
}), | ||
// @ts-ignore | ||
commonjs({ | ||
extensions: [".js", ".ts"] | ||
}), | ||
// @ts-ignore | ||
resolve({ | ||
preferBuiltins: true, | ||
extensions: [".js", ".ts"] | ||
}) | ||
] | ||
}; |
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,71 @@ | ||
import ApiGatewaySigner, { HttpMethods, SignedRequestData } from "./index"; | ||
import { Jest } from "@jest/environment"; | ||
|
||
const BASE_URL = "https://example.com"; | ||
|
||
describe("signRequest", () => { | ||
let signer: ApiGatewaySigner; | ||
beforeEach(() => { | ||
signer = new ApiGatewaySigner({ | ||
endpoint: BASE_URL | ||
}); | ||
}); | ||
|
||
test("headers are created", () => { | ||
const request = signer.signRequest({ | ||
method: HttpMethods.GET, | ||
path: "/" | ||
}); | ||
|
||
expect(request.headers).toBeDefined(); | ||
expect(request.headers).toHaveProperty("Accept", "application/json"); | ||
expect(request.headers).toHaveProperty("Authorization"); | ||
expect(request.headers.Authorization).toMatch( | ||
/^AWS4-HMAC-SHA256\sCredential=.*,\s+SignedHeaders=.*,\s+Signature=/ | ||
); | ||
expect(request.headers).toHaveProperty("Content-Type", "application/json"); | ||
expect(request.headers).toHaveProperty("x-amz-date"); | ||
}); | ||
|
||
test("URL is created", () => { | ||
const request = signer.signRequest({ | ||
method: HttpMethods.GET, | ||
path: "/" | ||
}); | ||
|
||
expect(request).toHaveProperty("url", BASE_URL + "/"); | ||
}); | ||
|
||
test("URL has params", () => { | ||
const request = signer.signRequest({ | ||
method: HttpMethods.GET, | ||
path: "/", | ||
queryParams: { | ||
query: "TEST_QUERY" | ||
} | ||
}); | ||
|
||
expect(request).toHaveProperty("url"); | ||
expect(request.url).toMatch(/query=TEST_QUERY$/); | ||
}); | ||
|
||
test("Exponential backoff", async () => { | ||
const RETRY_COUNT = 3; | ||
|
||
const callback = jest.fn(async (req: SignedRequestData) => { | ||
throw new Error("Testing"); | ||
}); | ||
|
||
const result = await signer.makeRequestWithRetries( | ||
{ | ||
method: HttpMethods.GET, | ||
path: "/" | ||
}, | ||
callback, | ||
RETRY_COUNT | ||
); | ||
|
||
expect(callback).toHaveBeenCalledTimes(RETRY_COUNT); | ||
expect(result).toBeUndefined(); | ||
}, 10000); | ||
}); |
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.