Skip to content

Instantly share code, notes, and snippets.

@Pyrolistical
Created October 9, 2021 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pyrolistical/cbf97431d9b08d3f734dbd4ea60dc3ec to your computer and use it in GitHub Desktop.
Save Pyrolistical/cbf97431d9b08d3f734dbd4ea60dc3ec to your computer and use it in GitHub Desktop.
separate business layer from infrastructure layer before service.spec.js
import Service from './service';
test('teams with disqualified players cannot check-in', async () => {
const db = {
collection(collection) {
switch (collection) {
case 'playerDisqualifications': {
return {
find({teamID}) {
expect(teamID).toBe('some team id');
return {
async toArray() {
return [
{
teamID: 'some team id',
reason: 'was a big meanie'
}
]
}
};
}
};
}
case 'checkIns': {
return {
updateOne() {
throw new Error('unexpected updateOne to checkIns collection')
}
};
}
}
}
};
const service = Service(db);
await expect(service.checkIn('some team id')).rejects.toThrow();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment