Skip to content

Commit

Permalink
misc(ci/cd): Create initial Treaty Test for Elysia
Browse files Browse the repository at this point in the history
  • Loading branch information
xyzuan committed Nov 5, 2024
1 parent 1cc63a7 commit b4ae435
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-dev.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Build xyzuan-api-v2 Development Build

on:
push:
branches:
- dev
workflow_run:
workflows: ["Run Tests with Elysia Treaty"]
types: [completed]

jobs:
build:
Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/treaty-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Run Tests with Elysia Treaty

on:
push:
branches:
- dev

jobs:
test:
runs-on: ubuntu-latest

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

- name: Initialize Bun Environtment
uses: oven-sh/setup-bun@v2

- name: Declaring some Global Environtment vars
run: |
echo "PORT=3121" >> $GITHUB_ENV
echo "DOMAIN=localhost" >> $GITHUB_ENV
echo "NODE_ENV=dev" >> $GITHUB_ENV
echo "PASSWORD_PEPPER=${{ secrets.PASSWORD_PEPPER }}" >> $GITHUB_ENV
echo "DATABASE_URL=${{ secrets.DATABASE_URL_DEV }}" >> $GITHUB_ENV
echo "GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }}" >> $GITHUB_ENV
echo "GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }}" >> $GITHUB_ENV
echo "GITHUB_CLIENT_ID=${{ secrets.GH_CLIENT_ID }}" >> $GITHUB_ENV
echo "GITHUB_CLIENT_SECRET=${{ secrets.GH_CLIENT_SECRET }}" >> $GITHUB_ENV
echo "LINKEDIN_CLIENT_ID=${{ secrets.LINKEDIN_CLIENT_ID }}" >> $GITHUB_ENV
echo "LINKEDIN_CLIENT_SECRET=${{ secrets.LINKEDIN_CLIENT_SECRET }}" >> $GITHUB_ENV
echo "TELEGRAM_TOKEN=${{ secrets.TELEGRAM_TOKEN }}" >> $GITHUB_ENV
echo "TELEGRAM_CHAT_ID=${{ secrets.TELEGRAM_CHAT_ID }}" >> $GITHUB_ENV
echo "CLOUDINARY_CLOUD_NAME=${{ secrets.CLOUDINARY_CLOUD_NAME }}" >> $GITHUB_ENV
echo "CLOUDINARY_API_KEY=${{ secrets.CLOUDINARY_API_KEY }}" >> $GITHUB_ENV
echo "CLOUDINARY_API_SECRET=${{ secrets.CLOUDINARY_API_SECRET }}" >> $GITHUB_ENV
- name: Run Treaty Tests
id: treaty_test
run: |
bun install
bunx prisma generate
bun test
echo "::set-output name=result::success"
- name: Mark as failed if tests fail
if: failure()
run: echo "::set-output name=result::failure"
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dependencies": {
"@bogeychan/elysia-logger": "^0.1.2",
"@elysiajs/cors": "^1.1.1",
"@elysiajs/eden": "^1.1.3",
"@elysiajs/swagger": "^1.1.1",
"@lucia-auth/adapter-prisma": "^4.0.1",
"@prisma/client": "5.19.1",
Expand Down
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
generator client {
provider = "prisma-client-js"
engineType = "binary"
binaryTargets = ["debian-openssl-3.0.x"]
binaryTargets = ["debian-openssl-3.0.x", "debian-openssl-1.1.x"]
}

datasource db {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import cors from "@elysiajs/cors";
import { docs } from "@libs/swagger";
import apiRoutes from "./api";

const api = baseElysia()
export const api = baseElysia()
.use(
cors({
origin: ["xyzuan.my.id", "localhost:3000", "localhost"],
Expand Down
23 changes: 23 additions & 0 deletions test/blog.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { describe, expect, it } from "bun:test";
import { api } from "../src";

describe("Blog Modules", () => {
it("Return a all blog list", async () => {
const response = await api
.handle(new Request("http://localhost:3121/v2/blog"))
.then(async (res) => await res.json());

expect(response).toHaveProperty("data");
expect(Array.isArray(response.data)).toBe(true);

const blog = response.data[0];
expect(blog).toHaveProperty("id");
expect(blog).toHaveProperty("title");
expect(blog).toHaveProperty("content");
expect(blog).toHaveProperty("commentsCount");
expect(blog).toHaveProperty("reactionsCount");

expect(blog.commentsCount).toBeGreaterThanOrEqual(0);
expect(blog.reactionsCount).toBeGreaterThanOrEqual(0);
});
});

0 comments on commit b4ae435

Please sign in to comment.