uranio 1.3.0 → 1.4.0
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.
- package/.uranio/package.json +1 -1
- package/.uranio/src/atom/mongodb.ts +8 -0
- package/.uranio/src/atom/mysql.ts +13 -0
- package/.uranio/src/atom/postgresql.ts +13 -0
- package/.uranio/tests/unit/atom/mongodb.test.ts +167 -0
- package/.uranio/tests/unit/atom/mysql.test.ts +140 -0
- package/.uranio/tests/unit/atom/postgresql.test.ts +140 -0
- package/package.json +1 -1
package/.uranio/package.json
CHANGED
|
@@ -157,6 +157,14 @@ export class MongoDBAtomClient<S extends atom_types.mongodb_atom> {
|
|
|
157
157
|
}
|
|
158
158
|
return (response as S);
|
|
159
159
|
}
|
|
160
|
+
|
|
161
|
+
public async countAtoms({where}: {where?: where_types.Where<S>}): Promise<number> {
|
|
162
|
+
where = _instance_object_id(where);
|
|
163
|
+
const count = await this.collection.countDocuments(
|
|
164
|
+
where as mongodb.Filter<S>
|
|
165
|
+
);
|
|
166
|
+
return count;
|
|
167
|
+
}
|
|
160
168
|
}
|
|
161
169
|
|
|
162
170
|
// type StringId<T extends unknown> = T extends {_id: any}
|
|
@@ -106,4 +106,17 @@ export class MySQLAtomClient<S extends atom_types.mysql_atom> {
|
|
|
106
106
|
const response = await this.client.exe(query);
|
|
107
107
|
return response;
|
|
108
108
|
}
|
|
109
|
+
|
|
110
|
+
public async countAtoms(where?: where_types.Where<S>): Promise<number> {
|
|
111
|
+
const query = sql.build.select({
|
|
112
|
+
projection: ['COUNT(*) as count'],
|
|
113
|
+
table: this.name,
|
|
114
|
+
where,
|
|
115
|
+
});
|
|
116
|
+
const [rows] = await this.client.exe(query);
|
|
117
|
+
if (Array.isArray(rows) && rows[0]) {
|
|
118
|
+
return (rows[0] as any).count || 0;
|
|
119
|
+
}
|
|
120
|
+
return 0;
|
|
121
|
+
}
|
|
109
122
|
}
|
|
@@ -106,4 +106,17 @@ export class PostgreSQLAtomClient<S extends atom_types.postgresql_atom> {
|
|
|
106
106
|
const response = await this.client.exe(query);
|
|
107
107
|
return response;
|
|
108
108
|
}
|
|
109
|
+
|
|
110
|
+
public async countAtoms(where?: where_types.Where<S>): Promise<number> {
|
|
111
|
+
const query = sql.build.select({
|
|
112
|
+
projection: ['COUNT(*) as count'],
|
|
113
|
+
table: this.name,
|
|
114
|
+
where,
|
|
115
|
+
});
|
|
116
|
+
const [rows] = await this.client.exe(query);
|
|
117
|
+
if (Array.isArray(rows) && rows[0]) {
|
|
118
|
+
return (rows[0] as any).count || 0;
|
|
119
|
+
}
|
|
120
|
+
return 0;
|
|
121
|
+
}
|
|
109
122
|
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for MongoDB Atom Client
|
|
3
|
+
* Tests atom methods with mocked database connections
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {MongoDBAtomClient} from '../../../src/atom/mongodb';
|
|
7
|
+
import {ObjectId} from 'mongodb';
|
|
8
|
+
|
|
9
|
+
type TestAtom = {
|
|
10
|
+
_id: ObjectId;
|
|
11
|
+
name: string;
|
|
12
|
+
age: number;
|
|
13
|
+
email: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
describe('MongoDBAtomClient', () => {
|
|
17
|
+
let mockDb: any;
|
|
18
|
+
let mockCollection: any;
|
|
19
|
+
let atomClient: MongoDBAtomClient<TestAtom>;
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
mockCollection = {
|
|
23
|
+
countDocuments: jest.fn(),
|
|
24
|
+
findOne: jest.fn(),
|
|
25
|
+
find: jest.fn(),
|
|
26
|
+
insertOne: jest.fn(),
|
|
27
|
+
insertMany: jest.fn(),
|
|
28
|
+
updateOne: jest.fn(),
|
|
29
|
+
updateMany: jest.fn(),
|
|
30
|
+
deleteOne: jest.fn(),
|
|
31
|
+
deleteMany: jest.fn(),
|
|
32
|
+
aggregate: jest.fn(),
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
mockDb = {
|
|
36
|
+
collection: jest.fn().mockReturnValue(mockCollection),
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
atomClient = new MongoDBAtomClient(mockDb, 'test_collection');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('countAtoms', () => {
|
|
43
|
+
it('should count all atoms without WHERE clause', async () => {
|
|
44
|
+
mockCollection.countDocuments.mockResolvedValue(42);
|
|
45
|
+
|
|
46
|
+
const count = await atomClient.countAtoms({});
|
|
47
|
+
|
|
48
|
+
expect(count).toBe(42);
|
|
49
|
+
expect(mockCollection.countDocuments).toHaveBeenCalledTimes(1);
|
|
50
|
+
expect(mockCollection.countDocuments).toHaveBeenCalledWith(undefined);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should count atoms with simple WHERE clause', async () => {
|
|
54
|
+
mockCollection.countDocuments.mockResolvedValue(10);
|
|
55
|
+
|
|
56
|
+
const count = await atomClient.countAtoms({where: {age: 25}});
|
|
57
|
+
|
|
58
|
+
expect(count).toBe(10);
|
|
59
|
+
expect(mockCollection.countDocuments).toHaveBeenCalledTimes(1);
|
|
60
|
+
expect(mockCollection.countDocuments).toHaveBeenCalledWith({age: 25});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should count atoms with comparison operators', async () => {
|
|
64
|
+
mockCollection.countDocuments.mockResolvedValue(5);
|
|
65
|
+
|
|
66
|
+
const count = await atomClient.countAtoms({where: {age: {$gte: 18}}});
|
|
67
|
+
|
|
68
|
+
expect(count).toBe(5);
|
|
69
|
+
expect(mockCollection.countDocuments).toHaveBeenCalledTimes(1);
|
|
70
|
+
expect(mockCollection.countDocuments).toHaveBeenCalledWith({age: {$gte: 18}});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should count atoms with multiple WHERE conditions', async () => {
|
|
74
|
+
mockCollection.countDocuments.mockResolvedValue(3);
|
|
75
|
+
|
|
76
|
+
const count = await atomClient.countAtoms({
|
|
77
|
+
where: {
|
|
78
|
+
age: {$gte: 18},
|
|
79
|
+
name: 'John',
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
expect(count).toBe(3);
|
|
84
|
+
expect(mockCollection.countDocuments).toHaveBeenCalledTimes(1);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should return 0 when no documents match', async () => {
|
|
88
|
+
mockCollection.countDocuments.mockResolvedValue(0);
|
|
89
|
+
|
|
90
|
+
const count = await atomClient.countAtoms({where: {name: 'NonExistent'}});
|
|
91
|
+
|
|
92
|
+
expect(count).toBe(0);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should count atoms with $in operator', async () => {
|
|
96
|
+
mockCollection.countDocuments.mockResolvedValue(15);
|
|
97
|
+
|
|
98
|
+
const count = await atomClient.countAtoms({
|
|
99
|
+
where: {
|
|
100
|
+
name: {$in: ['John', 'Jane', 'Bob']},
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
expect(count).toBe(15);
|
|
105
|
+
expect(mockCollection.countDocuments).toHaveBeenCalledTimes(1);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should count atoms with $or operator', async () => {
|
|
109
|
+
mockCollection.countDocuments.mockResolvedValue(20);
|
|
110
|
+
|
|
111
|
+
const count = await atomClient.countAtoms({
|
|
112
|
+
where: {
|
|
113
|
+
$or: [{age: {$lt: 18}}, {age: {$gt: 65}}],
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
expect(count).toBe(20);
|
|
118
|
+
expect(mockCollection.countDocuments).toHaveBeenCalledTimes(1);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('should handle large counts', async () => {
|
|
122
|
+
mockCollection.countDocuments.mockResolvedValue(1000000);
|
|
123
|
+
|
|
124
|
+
const count = await atomClient.countAtoms({});
|
|
125
|
+
|
|
126
|
+
expect(count).toBe(1000000);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('should convert string _id to ObjectId', async () => {
|
|
130
|
+
const testId = '507f1f77bcf86cd799439011';
|
|
131
|
+
mockCollection.countDocuments.mockResolvedValue(1);
|
|
132
|
+
|
|
133
|
+
const count = await atomClient.countAtoms({
|
|
134
|
+
where: {_id: testId as any},
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
expect(count).toBe(1);
|
|
138
|
+
expect(mockCollection.countDocuments).toHaveBeenCalledTimes(1);
|
|
139
|
+
const callArgs = mockCollection.countDocuments.mock.calls[0][0];
|
|
140
|
+
expect(callArgs._id).toBeInstanceOf(ObjectId);
|
|
141
|
+
expect(callArgs._id.toString()).toBe(testId);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('should handle ObjectId in nested where conditions', async () => {
|
|
145
|
+
const testId = '507f1f77bcf86cd799439011';
|
|
146
|
+
mockCollection.countDocuments.mockResolvedValue(5);
|
|
147
|
+
|
|
148
|
+
const count = await atomClient.countAtoms({
|
|
149
|
+
where: {
|
|
150
|
+
$or: [{_id: testId as any}, {name: 'John'}],
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
expect(count).toBe(5);
|
|
155
|
+
expect(mockCollection.countDocuments).toHaveBeenCalledTimes(1);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('should count with empty where object', async () => {
|
|
159
|
+
mockCollection.countDocuments.mockResolvedValue(100);
|
|
160
|
+
|
|
161
|
+
const count = await atomClient.countAtoms({where: {}});
|
|
162
|
+
|
|
163
|
+
expect(count).toBe(100);
|
|
164
|
+
expect(mockCollection.countDocuments).toHaveBeenCalledWith({});
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for MySQL Atom Client
|
|
3
|
+
* Tests atom methods with mocked database connections
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {MySQLAtomClient} from '../../../src/atom/mysql';
|
|
7
|
+
import {MySQLClient} from '../../../src/client/mysql';
|
|
8
|
+
|
|
9
|
+
type TestAtom = {
|
|
10
|
+
_id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
age: number;
|
|
13
|
+
email: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
describe('MySQLAtomClient', () => {
|
|
17
|
+
let mockClient: MySQLClient;
|
|
18
|
+
let atomClient: MySQLAtomClient<TestAtom>;
|
|
19
|
+
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
mockClient = {
|
|
22
|
+
exe: jest.fn(),
|
|
23
|
+
} as any;
|
|
24
|
+
atomClient = new MySQLAtomClient(mockClient, 'test_table');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('countAtoms', () => {
|
|
28
|
+
it('should count all atoms without WHERE clause', async () => {
|
|
29
|
+
const mockResult = [[{count: 42}], []];
|
|
30
|
+
(mockClient.exe as jest.Mock).mockResolvedValue(mockResult);
|
|
31
|
+
|
|
32
|
+
const count = await atomClient.countAtoms();
|
|
33
|
+
|
|
34
|
+
expect(count).toBe(42);
|
|
35
|
+
expect(mockClient.exe).toHaveBeenCalledTimes(1);
|
|
36
|
+
const callArgs = (mockClient.exe as jest.Mock).mock.calls[0][0];
|
|
37
|
+
const {sql} = callArgs.mysql();
|
|
38
|
+
expect(sql).toContain('SELECT COUNT(*) as count');
|
|
39
|
+
expect(sql).toContain('FROM `test_table`');
|
|
40
|
+
expect(sql).not.toContain('WHERE');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should count atoms with simple WHERE clause', async () => {
|
|
44
|
+
const mockResult = [[{count: 10}], []];
|
|
45
|
+
(mockClient.exe as jest.Mock).mockResolvedValue(mockResult);
|
|
46
|
+
|
|
47
|
+
const count = await atomClient.countAtoms({age: 25});
|
|
48
|
+
|
|
49
|
+
expect(count).toBe(10);
|
|
50
|
+
expect(mockClient.exe).toHaveBeenCalledTimes(1);
|
|
51
|
+
const callArgs = (mockClient.exe as jest.Mock).mock.calls[0][0];
|
|
52
|
+
const {sql} = callArgs.mysql();
|
|
53
|
+
expect(sql).toContain('SELECT COUNT(*) as count');
|
|
54
|
+
expect(sql).toContain('WHERE');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should count atoms with comparison operators', async () => {
|
|
58
|
+
const mockResult = [[{count: 5}], []];
|
|
59
|
+
(mockClient.exe as jest.Mock).mockResolvedValue(mockResult);
|
|
60
|
+
|
|
61
|
+
const count = await atomClient.countAtoms({age: {$gte: 18}});
|
|
62
|
+
|
|
63
|
+
expect(count).toBe(5);
|
|
64
|
+
expect(mockClient.exe).toHaveBeenCalledTimes(1);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should count atoms with multiple WHERE conditions', async () => {
|
|
68
|
+
const mockResult = [[{count: 3}], []];
|
|
69
|
+
(mockClient.exe as jest.Mock).mockResolvedValue(mockResult);
|
|
70
|
+
|
|
71
|
+
const count = await atomClient.countAtoms({
|
|
72
|
+
age: {$gte: 18},
|
|
73
|
+
name: 'John',
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
expect(count).toBe(3);
|
|
77
|
+
expect(mockClient.exe).toHaveBeenCalledTimes(1);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should return 0 when no rows match', async () => {
|
|
81
|
+
const mockResult = [[{count: 0}], []];
|
|
82
|
+
(mockClient.exe as jest.Mock).mockResolvedValue(mockResult);
|
|
83
|
+
|
|
84
|
+
const count = await atomClient.countAtoms({name: 'NonExistent'});
|
|
85
|
+
|
|
86
|
+
expect(count).toBe(0);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should return 0 when result is empty', async () => {
|
|
90
|
+
const mockResult = [[], []];
|
|
91
|
+
(mockClient.exe as jest.Mock).mockResolvedValue(mockResult);
|
|
92
|
+
|
|
93
|
+
const count = await atomClient.countAtoms();
|
|
94
|
+
|
|
95
|
+
expect(count).toBe(0);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('should return 0 when count is null', async () => {
|
|
99
|
+
const mockResult = [[{count: null}], []];
|
|
100
|
+
(mockClient.exe as jest.Mock).mockResolvedValue(mockResult);
|
|
101
|
+
|
|
102
|
+
const count = await atomClient.countAtoms();
|
|
103
|
+
|
|
104
|
+
expect(count).toBe(0);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('should count atoms with $in operator', async () => {
|
|
108
|
+
const mockResult = [[{count: 15}], []];
|
|
109
|
+
(mockClient.exe as jest.Mock).mockResolvedValue(mockResult);
|
|
110
|
+
|
|
111
|
+
const count = await atomClient.countAtoms({
|
|
112
|
+
name: {$in: ['John', 'Jane', 'Bob']},
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
expect(count).toBe(15);
|
|
116
|
+
expect(mockClient.exe).toHaveBeenCalledTimes(1);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('should count atoms with $or operator', async () => {
|
|
120
|
+
const mockResult = [[{count: 20}], []];
|
|
121
|
+
(mockClient.exe as jest.Mock).mockResolvedValue(mockResult);
|
|
122
|
+
|
|
123
|
+
const count = await atomClient.countAtoms({
|
|
124
|
+
$or: [{age: {$lt: 18}}, {age: {$gt: 65}}],
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
expect(count).toBe(20);
|
|
128
|
+
expect(mockClient.exe).toHaveBeenCalledTimes(1);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('should handle large counts', async () => {
|
|
132
|
+
const mockResult = [[{count: 1000000}], []];
|
|
133
|
+
(mockClient.exe as jest.Mock).mockResolvedValue(mockResult);
|
|
134
|
+
|
|
135
|
+
const count = await atomClient.countAtoms();
|
|
136
|
+
|
|
137
|
+
expect(count).toBe(1000000);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for PostgreSQL Atom Client
|
|
3
|
+
* Tests atom methods with mocked database connections
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {PostgreSQLAtomClient} from '../../../src/atom/postgresql';
|
|
7
|
+
import {PostgreSQLClient} from '../../../src/client/postgresql';
|
|
8
|
+
|
|
9
|
+
type TestAtom = {
|
|
10
|
+
_id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
age: number;
|
|
13
|
+
email: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
describe('PostgreSQLAtomClient', () => {
|
|
17
|
+
let mockClient: PostgreSQLClient;
|
|
18
|
+
let atomClient: PostgreSQLAtomClient<TestAtom>;
|
|
19
|
+
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
mockClient = {
|
|
22
|
+
exe: jest.fn(),
|
|
23
|
+
} as any;
|
|
24
|
+
atomClient = new PostgreSQLAtomClient(mockClient, 'test_table');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('countAtoms', () => {
|
|
28
|
+
it('should count all atoms without WHERE clause', async () => {
|
|
29
|
+
const mockResult = [[{count: 42}], []];
|
|
30
|
+
(mockClient.exe as jest.Mock).mockResolvedValue(mockResult);
|
|
31
|
+
|
|
32
|
+
const count = await atomClient.countAtoms();
|
|
33
|
+
|
|
34
|
+
expect(count).toBe(42);
|
|
35
|
+
expect(mockClient.exe).toHaveBeenCalledTimes(1);
|
|
36
|
+
const callArgs = (mockClient.exe as jest.Mock).mock.calls[0][0];
|
|
37
|
+
const {sql} = callArgs.postgres();
|
|
38
|
+
expect(sql).toContain('SELECT COUNT(*) as count');
|
|
39
|
+
expect(sql).toContain('FROM `test_table`');
|
|
40
|
+
expect(sql).not.toContain('WHERE');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should count atoms with simple WHERE clause', async () => {
|
|
44
|
+
const mockResult = [[{count: 10}], []];
|
|
45
|
+
(mockClient.exe as jest.Mock).mockResolvedValue(mockResult);
|
|
46
|
+
|
|
47
|
+
const count = await atomClient.countAtoms({age: 25});
|
|
48
|
+
|
|
49
|
+
expect(count).toBe(10);
|
|
50
|
+
expect(mockClient.exe).toHaveBeenCalledTimes(1);
|
|
51
|
+
const callArgs = (mockClient.exe as jest.Mock).mock.calls[0][0];
|
|
52
|
+
const {sql} = callArgs.postgres();
|
|
53
|
+
expect(sql).toContain('SELECT COUNT(*) as count');
|
|
54
|
+
expect(sql).toContain('WHERE');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should count atoms with comparison operators', async () => {
|
|
58
|
+
const mockResult = [[{count: 5}], []];
|
|
59
|
+
(mockClient.exe as jest.Mock).mockResolvedValue(mockResult);
|
|
60
|
+
|
|
61
|
+
const count = await atomClient.countAtoms({age: {$gte: 18}});
|
|
62
|
+
|
|
63
|
+
expect(count).toBe(5);
|
|
64
|
+
expect(mockClient.exe).toHaveBeenCalledTimes(1);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should count atoms with multiple WHERE conditions', async () => {
|
|
68
|
+
const mockResult = [[{count: 3}], []];
|
|
69
|
+
(mockClient.exe as jest.Mock).mockResolvedValue(mockResult);
|
|
70
|
+
|
|
71
|
+
const count = await atomClient.countAtoms({
|
|
72
|
+
age: {$gte: 18},
|
|
73
|
+
name: 'John',
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
expect(count).toBe(3);
|
|
77
|
+
expect(mockClient.exe).toHaveBeenCalledTimes(1);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should return 0 when no rows match', async () => {
|
|
81
|
+
const mockResult = [[{count: 0}], []];
|
|
82
|
+
(mockClient.exe as jest.Mock).mockResolvedValue(mockResult);
|
|
83
|
+
|
|
84
|
+
const count = await atomClient.countAtoms({name: 'NonExistent'});
|
|
85
|
+
|
|
86
|
+
expect(count).toBe(0);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should return 0 when result is empty', async () => {
|
|
90
|
+
const mockResult = [[], []];
|
|
91
|
+
(mockClient.exe as jest.Mock).mockResolvedValue(mockResult);
|
|
92
|
+
|
|
93
|
+
const count = await atomClient.countAtoms();
|
|
94
|
+
|
|
95
|
+
expect(count).toBe(0);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('should return 0 when count is null', async () => {
|
|
99
|
+
const mockResult = [[{count: null}], []];
|
|
100
|
+
(mockClient.exe as jest.Mock).mockResolvedValue(mockResult);
|
|
101
|
+
|
|
102
|
+
const count = await atomClient.countAtoms();
|
|
103
|
+
|
|
104
|
+
expect(count).toBe(0);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('should count atoms with $in operator', async () => {
|
|
108
|
+
const mockResult = [[{count: 15}], []];
|
|
109
|
+
(mockClient.exe as jest.Mock).mockResolvedValue(mockResult);
|
|
110
|
+
|
|
111
|
+
const count = await atomClient.countAtoms({
|
|
112
|
+
name: {$in: ['John', 'Jane', 'Bob']},
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
expect(count).toBe(15);
|
|
116
|
+
expect(mockClient.exe).toHaveBeenCalledTimes(1);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('should count atoms with $or operator', async () => {
|
|
120
|
+
const mockResult = [[{count: 20}], []];
|
|
121
|
+
(mockClient.exe as jest.Mock).mockResolvedValue(mockResult);
|
|
122
|
+
|
|
123
|
+
const count = await atomClient.countAtoms({
|
|
124
|
+
$or: [{age: {$lt: 18}}, {age: {$gt: 65}}],
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
expect(count).toBe(20);
|
|
128
|
+
expect(mockClient.exe).toHaveBeenCalledTimes(1);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('should handle large counts', async () => {
|
|
132
|
+
const mockResult = [[{count: 1000000}], []];
|
|
133
|
+
(mockClient.exe as jest.Mock).mockResolvedValue(mockResult);
|
|
134
|
+
|
|
135
|
+
const count = await atomClient.countAtoms();
|
|
136
|
+
|
|
137
|
+
expect(count).toBe(1000000);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
});
|