async-labs / saas

Build your own SaaS business with SaaS boilerplate. Productive stack: React, Material-UI, Next, MobX, WebSockets, Express, Node, Mongoose, MongoDB. Written with TypeScript.
https://saas-app.async-await.com
MIT License
4.13k stars 688 forks source link

[chapter 4] slugify test fails to work because of unsupported mongo options #183

Closed michaelklem closed 2 years ago

michaelklem commented 2 years ago

In the slugify.test.ts file, the following options are no longer supported: const options = { useNewUrlParser: true, useCreateIndex: true, useFindAndModify: false, useUnifiedTopology: true, };

await mongoose.connect(process.env.MONGO_URL_TEST, options);

See mongoose 6 documentation

Commenting out the options results in passing tests.

Original code results in these errors: test/server/utils/slugify.test.ts:17:56 - error TS2769: No overload matches this call. Overload 1 of 3, '(uri: string, callback: CallbackWithoutResult): void', gave the following error. Argument of type '{ useNewUrlParser: boolean; useCreateIndex: boolean; useFindAndModify: boolean; useUnifiedTopology: boolean; }' is not assignable to parameter of type 'CallbackWithoutResult'. Type '{ useNewUrlParser: boolean; useCreateIndex: boolean; useFindAndModify: boolean; useUnifiedTopology: boolean; }' provides no match for the signature '(error: NativeError): void'. Overload 2 of 3, '(uri: string, options?: ConnectOptions): Promise<typeof import("mongoose")>', gave the following error. Type '{ useNewUrlParser: boolean; useCreateIndex: boolean; useFindAndModify: boolean; useUnifiedTopology: boolean; }' has no properties in common with type 'ConnectOptions'.

17     await mongoose.connect(process.env.MONGO_URL_TEST, options);

I tested with the code in the 4-end directory.

klyburke commented 2 years ago

@michaelklem Thanks for reporting and resolving! I confirm the error you found, and I confirm that your solution fixes the error.

We upgraded to Mongoose v6 in our May/June 2022 book update. I missed making proper changes to slugify.test.js. I appreciate that you caught it.