Last active
March 11, 2018 22:43
-
-
Save zackify/d491b96a646203153b5b6b3d6daa7712 to your computer and use it in GitHub Desktop.
mock.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
const getAppointments = Appointment => () => { | |
return Appointment.joins(:customer).where('customers.pays_a_lot = true').includes(:customer).order_by('customers.age DESC') | |
} | |
const dbmock = fakes => new Proxy({}, { | |
get: (target, name) => { | |
if(!fakes[name]) return this | |
return fakes[name] | |
} | |
) | |
test('gets appointments', () => { | |
let fakeAppointments = [{ id: 1, title: 'blah' }] | |
let appointments = getAppointments(dbmock({ order_by: () => fakeAppointments }))() | |
expect(appointments[0].title).toEqual('blah') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment