|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var assert = require('assert'); |
| 4 | +var sinon = require('sinon'); |
| 5 | +var uuid = require('uuid'); |
| 6 | + |
| 7 | +var ApiKey = require('../lib/resource/ApiKey'); |
| 8 | +var DataStore = require('../lib/ds/DataStore'); |
| 9 | + |
| 10 | +describe('resource', function() { |
| 11 | + describe('ApiKey', function() { |
| 12 | + var clientApiKeySecret, sandbox, cbSpy, apiKey, getResourceStub; |
| 13 | + |
| 14 | + before(function(done) { |
| 15 | + clientApiKeySecret = uuid(); |
| 16 | + sandbox = sinon.sandbox.create(); |
| 17 | + cbSpy = sandbox.spy(); |
| 18 | + |
| 19 | + apiKey = new ApiKey({ |
| 20 | + id: 'id', |
| 21 | + secret: 'secret', |
| 22 | + account: { |
| 23 | + href: '/boom' |
| 24 | + } |
| 25 | + }); |
| 26 | + |
| 27 | + apiKey.dataStore = new DataStore({ |
| 28 | + client: { |
| 29 | + apiKey: { |
| 30 | + id: '1', |
| 31 | + secret: clientApiKeySecret |
| 32 | + } |
| 33 | + } |
| 34 | + }); |
| 35 | + |
| 36 | + getResourceStub = sinon.stub(apiKey.dataStore, 'getResource', function() { |
| 37 | + var args = Array.prototype.slice.call(arguments); |
| 38 | + var href = args.shift(); |
| 39 | + var callback = args.pop(); |
| 40 | + callback(null, {href: href}); |
| 41 | + }); |
| 42 | + |
| 43 | + done(); |
| 44 | + }); |
| 45 | + |
| 46 | + after(function() { |
| 47 | + sandbox.restore(); |
| 48 | + }); |
| 49 | + |
| 50 | + it('should provide a getAccount method', function() { |
| 51 | + assert(typeof apiKey.getAccount === 'function'); |
| 52 | + }); |
| 53 | + |
| 54 | + describe('getAccount', function() { |
| 55 | + it('should return an Account object', function(done) { |
| 56 | + apiKey.getAccount(function(err, account) { |
| 57 | + if (err) { |
| 58 | + return done(err); |
| 59 | + } |
| 60 | + |
| 61 | + assert(account.href === '/boom'); |
| 62 | + assert(getResourceStub.calledOnce); |
| 63 | + |
| 64 | + done(); |
| 65 | + }); |
| 66 | + }); |
| 67 | + }); |
| 68 | + }); |
| 69 | +}); |
0 commit comments