purest.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. const fs = require('fs')
  2. class MockPurest {
  3. constructor (opts) {
  4. const methodsToMock = ['query', 'select', 'where', 'qs', 'auth', 'get', 'put', 'post', 'options', 'json']
  5. methodsToMock.forEach((item) => {
  6. this[item] = () => this
  7. })
  8. this.opts = opts
  9. }
  10. request (done) {
  11. if (typeof done === 'function') {
  12. const responses = {
  13. dropbox: {
  14. hash: '0a9f95a989dd4b1851f0103c31e304ce',
  15. user_email: 'foo@bar.com',
  16. email: 'foo@bar.com',
  17. entries: [{ rev: 'f24234cd4' }]
  18. },
  19. drive: {
  20. kind: 'drive#fileList',
  21. etag: '"bcIyJ9A3gXa8oTYmz6nzAjQd-lY/eQc3WbZHkXpcItNyGKDuKXM_bNY"',
  22. files: [{
  23. id: '0B2x-PmqQHSKdT013TE1VVjZ3TWs',
  24. mimeType: 'image/jpg',
  25. ownedByMe: true,
  26. permissions: [{ role: 'owner', emailAddress: 'ife@bala.com' }]
  27. }],
  28. size: 300
  29. }
  30. }
  31. const body = responses[this.opts.providerName]
  32. done(null, { body, statusCode: 200 }, body)
  33. }
  34. return this
  35. }
  36. on (evt, cb) {
  37. if (evt === 'response') {
  38. cb(fs.createReadStream('./README.md'))
  39. }
  40. return this
  41. }
  42. }
  43. module.exports = () => {
  44. return (options) => new MockPurest(options)
  45. }