@syntropix/database 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,141 +0,0 @@
1
- import { BaseModel, Column } from '@/types/basemodel';
2
- import { AND, EQ, OR } from '@/types/filter';
3
-
4
- import 'dotenv/config';
5
-
6
- const getRandomString = () => {
7
- return Math.random().toString(36).substring(2, 15);
8
- };
9
-
10
- class User extends BaseModel {
11
- static tableName = `test_users_${getRandomString()}`;
12
-
13
- @Column({ type: 'Integer', primary: true, auto_increment: true })
14
- declare id: number;
15
-
16
- @Column()
17
- declare email: string;
18
-
19
- @Column({ name: 'full_name' })
20
- declare fullName: string;
21
-
22
- @Column({ type: 'Json', nullable: true })
23
- declare profile: any;
24
-
25
- @Column({ type: 'Boolean', name: 'is_active' })
26
- declare isActive: boolean;
27
- }
28
-
29
- describe('BaseModel ORM', () => {
30
- beforeAll(async () => {
31
- await User.createTable();
32
- });
33
-
34
- describe('User CRUD Operations', () => {
35
- let userId: number;
36
- let userEmail: string;
37
- let userFullName: string;
38
-
39
- test('should create a user', async () => {
40
- const randomValue = getRandomString();
41
- userEmail = `user${randomValue}@example.com`;
42
- userFullName = `User ${randomValue}`;
43
- const userCreateResp = await User.create({
44
- email: userEmail,
45
- fullName: userFullName,
46
- isActive: true,
47
- });
48
-
49
- expect(userCreateResp).toBeDefined();
50
- expect(userCreateResp.pk).toBeDefined();
51
- userId = userCreateResp.pk;
52
- });
53
-
54
- test('should retrieve the created user by id', async () => {
55
- const user = await User.get(OR(AND(EQ('id', userId))));
56
- expect(user).toBeDefined();
57
- expect(user.email).toBe(userEmail);
58
- expect(user.fullName).toBe(userFullName);
59
- expect(user.isActive).toBe(true);
60
- expect(user.profile).toBeNull();
61
- });
62
-
63
- test('should update a user', async () => {
64
- const user = await User.get(OR(AND(EQ('id', userId))));
65
- userFullName = `User ${getRandomString()}`;
66
- user.fullName = userFullName;
67
- await user.save();
68
-
69
- const updatedUser = await User.get(OR(AND(EQ('id', userId))));
70
- expect(updatedUser.fullName).toBe(userFullName);
71
- });
72
-
73
- test('should filter users by active status', async () => {
74
- const activeUsers = await User.filter({
75
- filter: OR(AND(EQ('is_active', true))),
76
- limit: 10,
77
- });
78
-
79
- expect(activeUsers).toBeDefined();
80
- expect(Array.isArray(activeUsers)).toBe(true);
81
- activeUsers.forEach((user) => {
82
- expect(user.isActive).toBe(true);
83
- });
84
- });
85
-
86
- test('should count users by active status', async () => {
87
- const userCount = await User.count({
88
- filter: OR(AND(EQ('is_active', true))),
89
- });
90
-
91
- expect(userCount).toBeDefined();
92
- expect(typeof userCount).toBe('number');
93
- expect(userCount).toBeGreaterThanOrEqual(0);
94
- });
95
-
96
- test('should delete a user', async () => {
97
- const user = await User.get(OR(AND(EQ('id', userId))));
98
- await user.remove();
99
-
100
- // Verify user is deleted (this might throw or return null depending on implementation)
101
- await expect(User.get(OR(AND(EQ('id', userId))))).rejects.toThrow();
102
- });
103
- });
104
-
105
- describe('Bulk Operations', () => {
106
- test('should bulk create multiple users', async () => {
107
- const users = await User.bulkCreate([
108
- {
109
- email: 'user2@example.com',
110
- fullName: 'User 2',
111
- isActive: true,
112
- },
113
- {
114
- email: 'user3@example.com',
115
- fullName: 'User 3',
116
- isActive: false,
117
- },
118
- ]);
119
-
120
- expect(users).toBeDefined();
121
- expect(users).toBe(2);
122
- });
123
-
124
- test('should retrieve bulk created users', async () => {
125
- const user2 = await User.get(OR(AND(EQ('email', 'user2@example.com'))));
126
- const user3 = await User.get(OR(AND(EQ('email', 'user3@example.com'))));
127
-
128
- expect(user2).toBeDefined();
129
- expect(user2.fullName).toBe('User 2');
130
- expect(user2.isActive).toBe(true);
131
-
132
- expect(user3).toBeDefined();
133
- expect(user3.fullName).toBe('User 3');
134
- expect(user3.isActive).toBe(false);
135
- });
136
- });
137
-
138
- afterAll(async () => {
139
- await User.dropTable();
140
- });
141
- });
@@ -1,8 +0,0 @@
1
- // This file is used to let VSCode respect the tsconfig.json for this test folder
2
- {
3
- "extends": "../tsconfig.json",
4
- "include": [".", "../src"],
5
- "compilerOptions": {
6
- "noEmit": true
7
- }
8
- }
package/tsconfig.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "ESNext",
5
- "moduleResolution": "Bundler",
6
- "esModuleInterop": true,
7
- "strict": true,
8
- "experimentalDecorators": true,
9
- "emitDecoratorMetadata": true,
10
- "baseUrl": ".",
11
- "paths": {
12
- "@/*": ["src/*"]
13
- },
14
- "outDir": "dist",
15
- "declaration": true
16
- },
17
- "include": ["src"]
18
- }