Created
October 9, 2021 21:17
-
-
Save Pyrolistical/cbf97431d9b08d3f734dbd4ea60dc3ec to your computer and use it in GitHub Desktop.
separate business layer from infrastructure layer before service.spec.js
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
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