Skip to content

Commit

Permalink
chore: Merge branch 'dev' of https://github.com/GDSC-Hongik/wow-class
Browse files Browse the repository at this point in the history
…into feature/layout
  • Loading branch information
ghdtjgus76 committed Aug 12, 2024
2 parents 8f5fcc6 + 178c622 commit 555f731
Show file tree
Hide file tree
Showing 13 changed files with 1,812 additions and 17 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/auto_assign.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Auto Assign

on:
pull_request:
types: [opened, ready_for_review, converted_to_draft]
issues:
types: [opened]

jobs:
assign_pull_request:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: hkusu/review-assign-action@v1
with:
assignees: ${{ github.actor }}

auto_assign_issue:
runs-on: ubuntu-latest
if: github.event_name == 'issues'
permissions:
issues: write
steps:
- name: "Auto-assign issue"
uses: pozil/auto-assign-issue@v2
with:
assignees: ${{ github.actor }}
40 changes: 40 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: build

on:
push:
branches:
- main
- dev
pull_request:
types: [opened, ready_for_review, converted_to_draft]
branches:
- main
- dev

jobs:
build:
runs-on: ubuntu-latest
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js 20.x
uses: actions/setup-node@v2
with:
node-version: 20.x

- name: Install pnpm
uses: pnpm/action-setup@v3
with:
version: 8
run_install: false

- name: Install dependencies
run: pnpm install

- name: Run build
run: pnpm run build
1 change: 1 addition & 0 deletions apps/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@types/react-dom": "^18",
"@wow-class/eslint-config": "workspace:*",
"@wow-class/typescript-config": "workspace:*",
"@wow-class/utils": "workspace:*",
"eslint": "^8",
"eslint-config-next": "^14.2.5",
"typescript": "^5"
Expand Down
1 change: 1 addition & 0 deletions apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@types/react-dom": "^18",
"@wow-class/eslint-config": "workspace:*",
"@wow-class/typescript-config": "workspace:*",
"@wow-class/utils": "workspace:*",
"eslint": "^8",
"eslint-config-next": "^14.2.5",
"typescript": "^5"
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ module.exports = {
],
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"turbo/no-undeclared-env-vars": "off",
},

settings: {
Expand All @@ -113,7 +114,6 @@ module.exports = {
version: "detect",
},
},

ignorePatterns: [
".*.js",
"node_modules/",
Expand Down
11 changes: 11 additions & 0 deletions packages/utils/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
root: true,
extends: ["@wow-class/eslint-config/basic.js"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: true,
ecmaVersion: 2020,
sourceType: "module",
},
};
10 changes: 10 additions & 0 deletions packages/utils/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
setupFiles: ["<rootDir>/jest.setup.ts"],
moduleFileExtensions: ["ts", "tsx", "js", "jsx"],
transform: {
"^.+\\.ts?$": "ts-jest",
},
testMatch: ["<rootDir>/**/*.(test|spec).ts"],
};
3 changes: 3 additions & 0 deletions packages/utils/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import fetchMock from "jest-fetch-mock";

fetchMock.enableMocks();
15 changes: 15 additions & 0 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@wow-class/utils",
"version": "0.0.0",
"private": true,
"scripts": {
"test": "jest"
},
"devDependencies": {
"@types/jest": "^29.5.12",
"jest": "^29.7.0",
"jest-fetch-mock": "^3.0.3",
"ts-jest": "^29.2.4",
"@wow-class/typescript-config": "workspace:*"
}
}
126 changes: 126 additions & 0 deletions packages/utils/src/fetcher/fetcher.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import fetchMock from "jest-fetch-mock";

import { fetcher } from "./fetcher";

describe("Fetcher", () => {
beforeEach(() => {
fetchMock.resetMocks();
});

it("should set the baseURL correctly", () => {
fetcher.setBaseUrl("https://api.example.com");

expect(fetcher["baseUrl"]).toBe("https://api.example.com");
});

it("should set default headers correctly", () => {
fetcher.setDefaultHeaders({ Authorization: "Bearer test-token" });

expect(fetcher["defaultHeaders"]).toEqual({
Authorization: "Bearer test-token",
});
});

it("should make a GET request with the correct headers and URL", async () => {
fetchMock.mockResponseOnce(JSON.stringify({ success: true }));
fetcher.setBaseUrl("https://api.example.com");
fetcher.setDefaultHeaders({
"Content-Type": "application/json",
Authorization: "Bearer test-token",
});

const response = await fetcher.get("/test-endpoint");

expect(fetchMock).toHaveBeenCalledWith(
"https://api.example.com/test-endpoint",
{
method: "GET",
headers: {
Authorization: "Bearer test-token",
"Content-Type": "application/json",
},
}
);
const jsonData = JSON.parse(response.data);
expect(jsonData).toEqual({ success: true });
});

it("should make a GET request with query parameters", async () => {
fetchMock.mockResponseOnce(JSON.stringify({ success: true }));
fetcher.setBaseUrl("https://api.example.com");
fetcher.setDefaultHeaders({
"Content-Type": "application/json",
Authorization: "Bearer test-token",
});

const params = { key1: "value1", key2: "value2" };
const response = await fetcher.get("/test-endpoint", {}, params);

expect(fetchMock).toHaveBeenCalledWith(
"https://api.example.com/test-endpoint?key1=value1&key2=value2",
{
method: "GET",
headers: {
Authorization: "Bearer test-token",
"Content-Type": "application/json",
},
}
);
const jsonData = JSON.parse(response.data);
expect(jsonData).toEqual({ success: true });
});

it("should make a POST request with the correct headers and URL and body", async () => {
fetchMock.mockResponseOnce(JSON.stringify({ success: true }));
fetcher.setBaseUrl("https://api.example.com");
fetcher.setDefaultHeaders({
"Content-Type": "application/json",
Authorization: "Bearer test-token",
});

const response = await fetcher.post("/test-endpoint", { foo: "bar" });

expect(fetchMock).toHaveBeenCalledWith(
"https://api.example.com/test-endpoint",
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer test-token",
},
body: JSON.stringify({ foo: "bar" }),
}
);
const jsonData = JSON.parse(response.data);
expect(jsonData).toEqual({ success: true });
});

it("should handle plain text responses", async () => {
fetchMock.mockResponseOnce("plain text response", {
headers: { "Content-Type": "text/plain" },
});
fetcher.setBaseUrl("https://api.example.com");

const response = await fetcher.get("/test-endpoint");
expect(response.data).toBe("plain text response");
});

it("should handle HTTP errors correctly", async () => {
fetchMock.mockResponseOnce("Not Found", { status: 404 });
fetcher.setBaseUrl("https://api.example.com");
fetcher.setDefaultHeaders({
"Content-Type": "application/json",
Authorization: "Bearer test-token",
});

try {
await fetcher.get("/test-endpoint");
} catch (error) {
expect(error).toBeInstanceOf(Error);
expect((error as any).response).toBeInstanceOf(Response);
expect((error as any).response.status).toBe(404);
expect((error as any).responseText).toBe("Not Found");
expect((error as any).message).toBe("HTTP Error: 404 Not Found");
}
});
});
Loading

0 comments on commit 555f731

Please sign in to comment.