Skip to content

Commit

Permalink
feat: added integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xcadams committed Dec 23, 2024
1 parent 1e7467d commit d250cf7
Show file tree
Hide file tree
Showing 17 changed files with 5,510 additions and 22 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Integration Test

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

jobs:
integration-test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]

steps:
- name: Checkout
uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 9
run_install: false

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"

- name: Install dependencies
run: pnpm install

- name: Run integration tests
run: cd integration && pnpm test
14 changes: 14 additions & 0 deletions integration/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Config } from "drizzle-kit";

if (!process.env.DATABASE_URL) {
throw new Error("DATABASE_URL is not defined.");
}

export default {
schema: "./drizzle/schema.ts",
out: "./drizzle",
dialect: "postgresql",
dbCredentials: {
url: "postgresql://user:[email protected]:5632/drizzle_zero",
},
} satisfies Config;
26 changes: 26 additions & 0 deletions integration/drizzle/0000_spicy_meteorite.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
CREATE DATABASE drizzle_zero;
CREATE DATABASE drizzle_zero_cvr;
CREATE DATABASE drizzle_zero_cdb;

\c drizzle_zero;

CREATE TABLE "medium" (
"id" text PRIMARY KEY NOT NULL,
"name" text NOT NULL
);
--> statement-breakpoint
CREATE TABLE "message" (
"id" text PRIMARY KEY NOT NULL,
"senderId" text,
"mediumId" text,
"body" text NOT NULL
);
--> statement-breakpoint
CREATE TABLE "user" (
"id" text PRIMARY KEY NOT NULL,
"name" text NOT NULL,
"partner" boolean NOT NULL
);
--> statement-breakpoint
ALTER TABLE "message" ADD CONSTRAINT "message_senderId_user_id_fk" FOREIGN KEY ("senderId") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "message" ADD CONSTRAINT "message_mediumId_medium_id_fk" FOREIGN KEY ("mediumId") REFERENCES "public"."medium"("id") ON DELETE no action ON UPDATE no action;
139 changes: 139 additions & 0 deletions integration/drizzle/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
"id": "aae07e9c-34a6-4917-ae21-19b574e9719c",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.medium": {
"name": "medium",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.message": {
"name": "message",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"senderId": {
"name": "senderId",
"type": "text",
"primaryKey": false,
"notNull": false
},
"mediumId": {
"name": "mediumId",
"type": "text",
"primaryKey": false,
"notNull": false
},
"body": {
"name": "body",
"type": "text",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {
"message_senderId_user_id_fk": {
"name": "message_senderId_user_id_fk",
"tableFrom": "message",
"tableTo": "user",
"columnsFrom": [
"senderId"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
},
"message_mediumId_medium_id_fk": {
"name": "message_mediumId_medium_id_fk",
"tableFrom": "message",
"tableTo": "medium",
"columnsFrom": [
"mediumId"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.user": {
"name": "user",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"partner": {
"name": "partner",
"type": "boolean",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
}
},
"enums": {},
"schemas": {},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
13 changes: 13 additions & 0 deletions integration/drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "7",
"dialect": "postgresql",
"entries": [
{
"idx": 0,
"version": "7",
"when": 1734976514122,
"tag": "0000_spicy_meteorite",
"breakpoints": true
}
]
}
20 changes: 20 additions & 0 deletions integration/drizzle/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { pgTable, text } from "drizzle-orm/pg-core";
import { boolean } from "drizzle-orm/pg-core";

export const user = pgTable("user", {
id: text("id").primaryKey(),
name: text("name").notNull(),
partner: boolean("partner").notNull(),
});

export const medium = pgTable("medium", {
id: text("id").primaryKey(),
name: text("name").notNull(),
});

export const message = pgTable("message", {
id: text("id").primaryKey(),
senderId: text("senderId").references(() => user.id),
mediumId: text("mediumId").references(() => medium.id),
body: text("body").notNull(),
});
24 changes: 24 additions & 0 deletions integration/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "drizzle-zero-integration",
"private": true,
"type": "module",
"scripts": {
"build-schema": "zero-build-schema -p schema.ts",
"db:generate": "drizzle-kit generate",
"test": "vitest run",
"postinstall": "pnpm run build-schema"
},
"dependencies": {
"drizzle-zero": "workspace:*"
},
"devDependencies": {
"@testcontainers/postgresql": "^10.16.0",
"@types/pg": "^8.11.10",
"@types/ws": "^8.5.13",
"@vitest/browser": "^2.1.8",
"drizzle-kit": "^0.30.1",
"pg": "^8.13.1",
"testcontainers": "^10.16.0",
"ws": "^8.18.0"
}
}
Loading

0 comments on commit d250cf7

Please sign in to comment.