Created
June 7, 2024 07:58
-
-
Save martinsson/dda36b037908ced85cb11b3a866bacf2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// inject a function that provides the interface under contract testing | |
function betRepositoryContract(getRepository: () => BetRepository) { | |
test('register a bets', async () => { | |
expect(true).toEqual(false); | |
}) | |
test('bets outside range are not retrieved', async () => { | |
expect(true).toEqual(false); | |
}) | |
} |
This file contains hidden or 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
// Do the initialisation ant then call the contract function | |
describe('MongoDbBetRepository', () => { | |
let mongoClient: MongoClient; | |
let repository: MongoDbBetRepository; | |
beforeEach(async () => { | |
mongoClient = new MongoClient('mongodb://localhost:27017'); | |
const db = await initDb(); | |
repository = new MongoDbBetRepository(db); | |
}) | |
betRepositoryContract(() => repository); | |
afterEach(() => { | |
mongoClient.close() | |
}) | |
async function initDb() { | |
await mongoClient.connect() | |
const db = mongoClient.db('contract_testing'); | |
await db.collection("bets").drop(); | |
return db; | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment