Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add workflow #5

Merged
merged 7 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/build-test-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build and test

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
main:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
with:
version: 8
- name: Setting up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"
- name: Enabling pre-post scripts
run: pnpm config set enable-pre-post-scripts true
- run: pnpm install
- run: pnpm lint
- name: Cache pnpm modules
uses: actions/cache@v4
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-
- run: pnpm build
- run: pnpm test:coverage
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
38 changes: 35 additions & 3 deletions lib/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getEnvironmentVariable,
createKindeAPI,
WorkflowEvents,
WorkflowTrigger,
} from "./main";

global.kinde = {
Expand All @@ -25,6 +26,38 @@ global.kinde = {
fetch: vi.fn().mockResolvedValue({}),
};

const mockEvent: WorkflowEvents = {
request: {
ip: "1.2.3.4",
auth: {
audience: ["https://api.example.com/v1"],
},
},
context: {
auth: {
origin: "refresh_token_request",
connectionId: "conn_0192b...",
isExistingSession: false,
},
user: {
id: "kp_6a071...",
identityId: "identity_0192c...",
},
domains: {
kindeDomain: "https://mykindebusiness.kinde.com",
},
workflow: {
trigger: WorkflowTrigger.UserTokenGeneration,
},
application: {
clientId: "f77dbc...",
},
organization: {
code: "org_b5a9c8...",
},
},
};

describe("ID Token", () => {
it("should return a proxy object with IdToken properties", () => {
const idTokenHandle = idTokenCustomClaims();
Expand Down Expand Up @@ -65,12 +98,11 @@ describe("getEnvironmentVariable", () => {

describe("createKindeAPI", () => {
it("should return the value of the environment variable", async () => {
const env = await createKindeAPI("API_KEY" as WorkflowEvents, {
method: "GET",
});
const env = await createKindeAPI(mockEvent);
expect(env).toStrictEqual({
delete: expect.any(Function),
get: expect.any(Function),
patch: expect.any(Function),
post: expect.any(Function),
put: expect.any(Function),
});
DanielRivers marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
10 changes: 5 additions & 5 deletions lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,14 @@ export async function createKindeAPI(

return {
get: async (params: Omit<KindeAPIRequest, "method">) =>
await callKindeAPI({ method: "GET", ...params}),
await callKindeAPI({ method: "GET", ...params }),
post: async (params: Omit<KindeAPIRequest, "method">) =>
await callKindeAPI({ method: "POST", ...params}),
await callKindeAPI({ method: "POST", ...params }),
patch: async (params: Omit<KindeAPIRequest, "method">) =>
await callKindeAPI({ method: "PATCH", ...params}),
await callKindeAPI({ method: "PATCH", ...params }),
put: async (params: Omit<KindeAPIRequest, "method">) =>
await callKindeAPI({ method: "PUT", ...params}),
await callKindeAPI({ method: "PUT", ...params }),
delete: async (params: Omit<KindeAPIRequest, "method">) =>
await callKindeAPI({ method: "DELETE", ...params}),
await callKindeAPI({ method: "DELETE", ...params }),
};
}
10 changes: 5 additions & 5 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ export type KindeFetchOptions = {
};

export type KindeAPIRequest = {
method: "POST" | "GET" | "PUT" | "DELETE" | "PATCH",
endpoint: string,
params?: Record<string, string>,
contentType?: "application/json" | "application/x-www-form-urlencoded"
}
method: "POST" | "GET" | "PUT" | "DELETE" | "PATCH";
endpoint: string;
params?: Record<string, string>;
contentType?: "application/json" | "application/x-www-form-urlencoded";
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"lint": "prettier --check . && eslint .",
"lint:fix": "prettier --write .",
"test": "vitest",
"test:coverage": "vitest --coverage"
Expand Down
Loading