-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Getting the following error because I used ObjectId from bson
● Test suite failed to run src/impl/mongoose/dao/MongooseDaoFactory.ts:45:5 - error TS2322: Type 'OfferDao' is not assignable to type 'IOfferDao<ObjectId, IOffer<ObjectId>>'. Types of property 'loadSubOffers' are incompatible. Type '(parentOfferId: ObjectId) => Promise<IMongooseOffer[]>' is not assignable to type '(parentOfferId: ObjectId) => Promise<IOffer<ObjectId>[]>'. Types of parameters 'parentOfferId' and 'parentOfferId' are incompatible. Type 'ObjectId' is missing the following properties from type 'ObjectId': _bsontype, id, toHexString, toJSON, and 3 more. 45 return this.offerDao; Known issue: Automattic/mongoose#12711 Automattic/mongoose#12537
- Loading branch information
zhamdi
committed
Oct 5, 2023
1 parent
1cc83f9
commit d5b4f4e
Showing
12 changed files
with
112 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,71 @@ | ||
/* global beforeAll, console, afterAll, expect */ | ||
// setup.js | ||
import { asValue } from "awilix"; | ||
import { MongoMemoryServer } from "mongodb-memory-server"; | ||
|
||
import { MongooseDaoFactory } from "../../src/impl/mongoose/dao/MongooseDaoFactory"; | ||
import { testContainer } from "../../test/testContainer"; | ||
|
||
let mongoServer; | ||
|
||
beforeAll(async () => { | ||
mongoServer = await MongoMemoryServer.create(); | ||
const uri = mongoServer.getUri(); | ||
console.log("URI for mongodb: ", uri); | ||
testContainer.register({ | ||
mongoUri: asValue(uri), // Register it as a value dependency | ||
}); | ||
const mongooseDaoFactory = new MongooseDaoFactory(uri, "userCredits"); | ||
testContainer.register({ mongooseDaoFactory: asValue(mongooseDaoFactory) }); | ||
|
||
// Use `uri` and `dbName` in your Awilix container setup. | ||
// Register them as constants or inject them as needed. | ||
}); | ||
|
||
afterAll(async () => { | ||
await mongoServer.stop(); | ||
// FIXME uncomment the following line: it's commented to allow us to connect and check the db for now | ||
// await mongoServer.stop(); | ||
}); | ||
|
||
// Define a Jest utility function to compare objects field by field | ||
expect.extend({ | ||
toHaveSameFields(received, expected) { | ||
const receivedKeys = Object.keys(received); | ||
const expectedKeys = Object.keys(expected); | ||
|
||
// Check if the number of fields is the same | ||
if (receivedKeys.length !== expectedKeys.length) { | ||
return { | ||
message: () => `Expected objects to have the same number of fields.`, | ||
pass: false, | ||
}; | ||
} | ||
|
||
const differences = []; | ||
|
||
// Compare fields and their values | ||
for (const key of receivedKeys) { | ||
const receivedValue = received[key]; | ||
const expectedValue = expected[key]; | ||
|
||
if (receivedValue !== expectedValue) { | ||
differences.push(key); | ||
} | ||
} | ||
|
||
// Determine if the objects have the same fields | ||
const pass = differences.length === 0; | ||
|
||
const message = pass | ||
? () => `Expected objects not to have the same fields.` | ||
: () => | ||
`Expected objects to have the same fields, but found differences in: ${differences.join( | ||
", ", | ||
)}.`; | ||
|
||
return { | ||
message, | ||
pass, | ||
}; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters