-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.ts
More file actions
53 lines (43 loc) · 1.45 KB
/
Copy pathmain_test.ts
File metadata and controls
53 lines (43 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import "reflect-metadata";
import "./src/deps.ts";
import { assertEquals } from "./src/deps.ts";
import { ModelRegistry } from "./src/models/ModelRegistry.ts";
import { Column, Entity, PrimaryKey } from "./src/decorators/index.ts";
import { BaseModel } from "./src/models/BaseModel.ts";
// Ensure migrations directory exists for all tests
import { ensureDir } from "https://deno.land/std@0.203.0/fs/mod.ts";
try {
await ensureDir("./migrations");
console.log("Migrations directory ensured");
} catch (error) {
// Proper error type checking
if (error instanceof Error) {
console.warn("Could not create migrations directory:", error.message);
} else {
console.warn("Could not create migrations directory:", String(error));
}
console.warn("If running tests, make sure to use --allow-write flag");
}
// Register base models first
@Entity({ tableName: "users" })
class User extends BaseModel {
@PrimaryKey()
id!: number;
@Column({ type: "varchar", length: 255 })
name!: string;
}
import { Post } from "./src/models/Post.ts";
ModelRegistry.registerModels(User, Post);
// Initialize reflect-metadata before running tests
Reflect.defineMetadata("validations", [], Object);
import { add } from "./main.ts";
Deno.test(function addTest() {
assertEquals(add(2, 3), 5);
});
Deno.test(function postCreationTest() {
const post = new Post();
post.title = "Sample Title";
if (!post.title) {
throw new Error("Post title was not set properly");
}
});