Skip to content

Commit df6f259

Browse files
committed
test: fix tests for mongoose v6 & v5
1 parent 39a6f22 commit df6f259

File tree

10 files changed

+26
-24
lines changed

10 files changed

+26
-24
lines changed

src/__tests__/__snapshots__/integration-test.ts.snap

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22

33
exports[`integration tests projection should request all fields to rawData field: projection from all fields 1`] = `
44
Array [
5-
"someDeep",
6-
"users",
7-
"skills",
8-
"employment",
9-
"contacts",
5+
"__v",
106
"_id",
11-
"n",
127
"age",
8+
"contacts",
9+
"createdAt",
10+
"employment",
1311
"gender",
14-
"relocation",
12+
"id",
1513
"languages",
16-
"periods",
17-
"createdAt",
18-
"updatedAt",
19-
"__v",
14+
"n",
2015
"name",
2116
"nameVirtual",
22-
"id",
17+
"periods",
18+
"relocation",
19+
"skills",
20+
"someDeep",
21+
"updatedAt",
22+
"users",
2323
]
2424
`;
2525

src/__tests__/github_issues/271-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ describe('nested projections with aliases - issue #271', () => {
9999
expect(book?.author?.age).toEqual(115);
100100
expect(book?.toObject({ virtuals: true })).toEqual({
101101
_id: 1,
102-
a: { ag: 115, age: 115, id: null },
103-
author: { ag: 115, age: 115, id: null },
102+
a: expect.objectContaining({ ag: 115, age: 115 }),
103+
author: expect.objectContaining({ ag: 115, age: 115 }),
104104
id: '1',
105105
pageCount: 1168,
106106
pc: 1168,

src/__tests__/integration-test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ describe('integration tests', () => {
165165
schema,
166166
'{ user(_id: "100000000000000000000000") { rawData } }'
167167
);
168-
expect(Object.keys(res.data.user.rawData)).toMatchSnapshot('projection from all fields');
168+
expect(Object.keys(res.data.user.rawData).sort()).toMatchSnapshot(
169+
'projection from all fields'
170+
);
169171
});
170172
});
171173
});

src/resolvers/__tests__/createOne-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe('createOne() ->', () => {
8989
});
9090

9191
const doc = await UserModel.collection.findOne({ _id: res.record._id });
92-
expect(doc.n).toBe(checkedName);
92+
expect(doc?.n).toBe(checkedName);
9393
});
9494

9595
it('should return payload.record when it requested', async () => {

src/resolvers/__tests__/dataLoader-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ describe('dataLoader() ->', () => {
161161
...resolveParams,
162162
});
163163

164-
const nonExistedId = mongoose.Types.ObjectId('5cefda4616156200084e5170');
164+
const nonExistedId = new mongoose.Types.ObjectId('5cefda4616156200084e5170');
165165
const resultPromise5 = resolver.resolve({
166166
args: { _id: nonExistedId },
167167
...resolveParams,

src/resolvers/__tests__/dataLoaderMany-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ describe('dataLoaderMany() ->', () => {
157157
...resolveParams,
158158
});
159159

160-
const nonExistedId = mongoose.Types.ObjectId('5cefda4616156200084e5170');
160+
const nonExistedId = new mongoose.Types.ObjectId('5cefda4616156200084e5170');
161161
const resultPromise3 = resolver.resolve({
162162
args: { _ids: [user._id, nonExistedId] },
163163
...resolveParams,

src/resolvers/__tests__/removeById-test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ describe('removeById() ->', () => {
164164
});
165165
await expect(result).rejects.toThrow('Denied due context ReadOnly');
166166
const exist = await UserModel.collection.findOne({ _id: user._id });
167-
expect(exist.n).toBe(user.name);
167+
expect(exist?.n).toBe(user.name);
168168
});
169169

170170
it('should call `beforeQuery` method with non-executed `query` as arg', async () => {
@@ -180,14 +180,14 @@ describe('removeById() ->', () => {
180180
beforeQuery(query: any, rp: ExtendedResolveParams) {
181181
expect(rp.model).toBe(UserModel);
182182
expect(rp.query).toHaveProperty('exec');
183-
return query.where({ _id: user._id, canDelete: false });
183+
return query.where({ _id: user._id, gender: 'some' });
184184
},
185185
};
186186

187187
const result = await removeById(UserModel, UserTC).resolve(resolveParams);
188188

189189
expect(mongooseActions).toEqual([
190-
['users', 'findOne', { _id: user._id, canDelete: false }, { projection: {} }],
190+
['users', 'findOne', { _id: user._id, gender: 'some' }, { projection: {} }],
191191
]);
192192

193193
expect(result).toBeNull();

src/resolvers/__tests__/removeOne-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ describe('removeOne() ->', () => {
215215
});
216216
await expect(result).rejects.toThrow('Denied due context ReadOnly');
217217
const exist = await UserModel.collection.findOne({ _id: user1._id });
218-
expect(exist.n).toBe(user1.name);
218+
expect(exist?.n).toBe(user1.name);
219219
});
220220

221221
it('should call `beforeQuery` method with non-executed `query` as arg', async () => {

src/resolvers/__tests__/updateById-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ describe('updateById() ->', () => {
240240
});
241241
await expect(result).rejects.toThrow('Denied due context ReadOnly');
242242
const exist = await UserModel.collection.findOne({ _id: user1._id });
243-
expect(exist.n).toBe(user1.name);
243+
expect(exist?.n).toBe(user1.name);
244244
});
245245

246246
it('should call `beforeQuery` method with non-executed `query` as arg', async () => {

src/resolvers/__tests__/updateOne-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ describe('updateOne() ->', () => {
294294
});
295295
await expect(result).rejects.toThrow('Denied due context ReadOnly');
296296
const exist = await UserModel.collection.findOne({ _id: user1._id });
297-
expect(exist.n).toBe(user1.name);
297+
expect(exist?.n).toBe(user1.name);
298298
});
299299

300300
it('should call `beforeQuery` method with non-executed `query` as arg', async () => {

0 commit comments

Comments
 (0)