Skip to content

Instantly share code, notes, and snippets.

@martinsson
Created June 7, 2024 07:58
Show Gist options
  • Save martinsson/dda36b037908ced85cb11b3a866bacf2 to your computer and use it in GitHub Desktop.
Save martinsson/dda36b037908ced85cb11b3a866bacf2 to your computer and use it in GitHub Desktop.
// 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);
})
}
// 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