Skip to content

Commit 4b402a9

Browse files
committed
test: relax typescript for options in mongoose.connect method in mongoose v6. Keep some time ability to pass tests with mongoose v5 without code changes
1 parent bd76a8e commit 4b402a9

File tree

10 files changed

+91
-26
lines changed

10 files changed

+91
-26
lines changed

src/__mocks__/mongooseCommon.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ mongoose.createConnection = (async () => {
1313
const mongoUri = mongoServer.getUri();
1414

1515
// originalConnect.bind(mongoose)(mongoUri, { useMongoClient: true }); // mongoose 4
16-
originalConnect.bind(mongoose)(mongoUri, {
17-
useNewUrlParser: true,
18-
useUnifiedTopology: true,
19-
useCreateIndex: true,
20-
}); // mongoose 5
16+
originalConnect.bind(mongoose)(
17+
mongoUri,
18+
{
19+
useNewUrlParser: true,
20+
useUnifiedTopology: true,
21+
} as any /* for tests compatibility with mongoose v5 & v6 */
22+
); // mongoose 5
23+
// originalConnect.bind(mongoose)(mongoUri, {}); // mongoose 6
2124

2225
mongoose.connection.on('error', (e) => {
2326
if (e.message.code === 'ETIMEDOUT') {

src/__tests__/github_issues/117-test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ let mongoServer: MongoMemoryServer;
66
beforeAll(async () => {
77
mongoServer = await MongoMemoryServer.create();
88
const mongoUri = mongoServer.getUri();
9-
await mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true });
9+
await mongoose.connect(
10+
mongoUri,
11+
{
12+
useNewUrlParser: true,
13+
useUnifiedTopology: true,
14+
} as any /* for tests compatibility with mongoose v5 & v6 */
15+
);
1016
});
1117

1218
afterAll(() => {

src/__tests__/github_issues/120-test.ts

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ let mongoServer: MongoMemoryServer;
88
beforeAll(async () => {
99
mongoServer = await MongoMemoryServer.create();
1010
const mongoUri = mongoServer.getUri();
11-
await mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true });
11+
await mongoose.connect(
12+
mongoUri,
13+
{
14+
useNewUrlParser: true,
15+
useUnifiedTopology: true,
16+
} as any /* for tests compatibility with mongoose v5 & v6 */
17+
);
1218
// mongoose.set('debug', true);
1319
});
1420

@@ -31,14 +37,16 @@ describe('issue #120 - check `connection` resolver with last/before', () => {
3137

3238
it('check last/before with sorting', async () => {
3339
const res1 = await resolver.resolve({ args: { last: 2, before: '', sort: { _id: 1 } } });
34-
expect(res1.edges.map(({ cursor, node }: any) => ({ cursor, node: node.toString() }))).toEqual([
40+
expect(
41+
res1.edges.map(({ cursor, node }: any) => ({ cursor, _id: node._id.toString() }))
42+
).toEqual([
3543
{
3644
cursor: 'eyJfaWQiOiIxMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDgifQ==',
37-
node: '{ _id: 100000000000000000000008 }',
45+
_id: '100000000000000000000008',
3846
},
3947
{
4048
cursor: 'eyJfaWQiOiIxMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDkifQ==',
41-
node: '{ _id: 100000000000000000000009 }',
49+
_id: '100000000000000000000009',
4250
},
4351
]);
4452

@@ -49,29 +57,35 @@ describe('issue #120 - check `connection` resolver with last/before', () => {
4957
sort: { _id: 1 },
5058
},
5159
});
52-
expect(res2.edges.map(({ cursor, node }: any) => ({ cursor, node: node.toString() }))).toEqual([
60+
expect(
61+
res2.edges.map(({ cursor, node }: any) => ({ cursor, _id: node._id.toString() }))
62+
).toEqual([
5363
{
5464
cursor: 'eyJfaWQiOiIxMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDYifQ==',
55-
node: '{ _id: 100000000000000000000006 }',
65+
_id: '100000000000000000000006',
5666
},
5767
{
5868
cursor: 'eyJfaWQiOiIxMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDcifQ==',
59-
node: '{ _id: 100000000000000000000007 }',
69+
_id: '100000000000000000000007',
6070
},
6171
]);
6272
});
6373

6474
it('check last/before without sorting', async () => {
6575
const res1 = await resolver.resolve({ args: { last: 2, before: '' } });
66-
expect(res1.edges.map(({ cursor, node }: any) => ({ cursor, node: node.toString() }))).toEqual([
67-
{ cursor: 'Nw==', node: "{ _id: 100000000000000000000008, title: '8', __v: 0 }" },
68-
{ cursor: 'OA==', node: "{ _id: 100000000000000000000009, title: '9', __v: 0 }" },
76+
expect(
77+
res1.edges.map(({ cursor, node }: any) => ({ cursor, _id: node._id.toString() }))
78+
).toEqual([
79+
{ cursor: 'Nw==', _id: '100000000000000000000008' },
80+
{ cursor: 'OA==', _id: '100000000000000000000009' },
6981
]);
7082

7183
const res2 = await resolver.resolve({ args: { last: 2, before: 'Nw==' } });
72-
expect(res2.edges.map(({ cursor, node }: any) => ({ cursor, node: node.toString() }))).toEqual([
73-
{ cursor: 'NQ==', node: "{ _id: 100000000000000000000006, title: '6', __v: 0 }" },
74-
{ cursor: 'Ng==', node: "{ _id: 100000000000000000000007, title: '7', __v: 0 }" },
84+
expect(
85+
res2.edges.map(({ cursor, node }: any) => ({ cursor, _id: node._id.toString() }))
86+
).toEqual([
87+
{ cursor: 'NQ==', _id: '100000000000000000000006' },
88+
{ cursor: 'Ng==', _id: '100000000000000000000007' },
7589
]);
7690
});
7791
});

src/__tests__/github_issues/128-test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ let mongoServer: MongoMemoryServer;
88
beforeAll(async () => {
99
mongoServer = await MongoMemoryServer.create();
1010
const mongoUri = mongoServer.getUri();
11-
await mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true });
11+
await mongoose.connect(
12+
mongoUri,
13+
{
14+
useNewUrlParser: true,
15+
useUnifiedTopology: true,
16+
} as any /* for tests compatibility with mongoose v5 & v6 */
17+
);
1218
// mongoose.set('debug', true);
1319
});
1420

src/__tests__/github_issues/135-test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ let mongoServer: MongoMemoryServer;
99
beforeAll(async () => {
1010
mongoServer = await MongoMemoryServer.create();
1111
const mongoUri = mongoServer.getUri();
12-
await mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true });
12+
await mongoose.connect(
13+
mongoUri,
14+
{
15+
useNewUrlParser: true,
16+
useUnifiedTopology: true,
17+
} as any /* for tests compatibility with mongoose v5 & v6 */
18+
);
1319
// mongoose.set('debug', true);
1420
});
1521

src/__tests__/github_issues/136-test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ let mongoServer: MongoMemoryServer;
99
beforeAll(async () => {
1010
mongoServer = await MongoMemoryServer.create();
1111
const mongoUri = mongoServer.getUri();
12-
await mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true });
12+
await mongoose.connect(
13+
mongoUri,
14+
{
15+
useNewUrlParser: true,
16+
useUnifiedTopology: true,
17+
} as any /* for tests compatibility with mongoose v5 & v6 */
18+
);
1319
// mongoose.set('debug', true);
1420
});
1521

src/__tests__/github_issues/157-test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ let mongoServer: MongoMemoryServer;
99
beforeAll(async () => {
1010
mongoServer = await MongoMemoryServer.create();
1111
const mongoUri = mongoServer.getUri();
12-
await mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true });
12+
await mongoose.connect(
13+
mongoUri,
14+
{
15+
useNewUrlParser: true,
16+
useUnifiedTopology: true,
17+
} as any /* for tests compatibility with mongoose v5 & v6 */
18+
);
1319
// mongoose.set('debug', true);
1420
});
1521

src/__tests__/github_issues/194-test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ let mongoServer: MongoMemoryServer;
99
beforeAll(async () => {
1010
mongoServer = await MongoMemoryServer.create();
1111
const mongoUri = mongoServer.getUri();
12-
await mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true });
12+
await mongoose.connect(
13+
mongoUri,
14+
{
15+
useNewUrlParser: true,
16+
useUnifiedTopology: true,
17+
} as any /* for tests compatibility with mongoose v5 & v6 */
18+
);
1319
// mongoose.set('debug', true);
1420
});
1521

src/__tests__/github_issues/248-test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ let mongoServer: MongoMemoryServer;
77
beforeAll(async () => {
88
mongoServer = await MongoMemoryServer.create();
99
const mongoUri = mongoServer.getUri();
10-
await mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true });
10+
await mongoose.connect(
11+
mongoUri,
12+
{
13+
useNewUrlParser: true,
14+
useUnifiedTopology: true,
15+
} as any /* for tests compatibility with mongoose v5 & v6 */
16+
);
1117
// mongoose.set('debug', true);
1218
});
1319

src/__tests__/github_issues/78-test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ let mongoServer: MongoMemoryServer;
77
beforeAll(async () => {
88
mongoServer = await MongoMemoryServer.create();
99
const mongoUri = mongoServer.getUri();
10-
await mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true });
10+
await mongoose.connect(
11+
mongoUri,
12+
{
13+
useNewUrlParser: true,
14+
useUnifiedTopology: true,
15+
} as any /* for tests compatibility with mongoose v5 & v6 */
16+
);
1117
});
1218

1319
afterAll(() => {

0 commit comments

Comments
 (0)