1 | async = require 'async'
|
2 | assert = require 'assert'
|
3 | _ = require 'underscore'
|
4 | nock = require 'nock'
|
5 | Clever = require "#{__dirname}/../index"
|
6 |
|
7 | describe 'get/set properties', ->
|
8 |
|
9 | before -> @clever = Clever 'DEMO_KEY', 'https://api.clever.com'
|
10 |
|
11 | after -> nock.cleanAll()
|
12 |
|
13 | it 'can hit second-level for properties', (done) ->
|
14 | nock('https://api.clever.com:443')
|
15 | .get('/v1.1/districts?where=%7B%22id%22%3A%224fd43cc56d11340000000005%22%7D&limit=1').reply(200,
|
16 | data: [
|
17 | data:
|
18 | name: 'Test District'
|
19 | id: '4fd43cc56d11340000000005'
|
20 | uri: '/v1.1/districts/4fd43cc56d11340000000005'
|
21 | ]
|
22 | ).get('/v1.1/districts/4fd43cc56d11340000000005/properties').reply(200,
|
23 | data:
|
24 | some: { really: { nested: 'property' } }
|
25 | ).patch('/v1.1/districts/4fd43cc56d11340000000005/properties', { test: 'data' }).reply(200,
|
26 | data:
|
27 | some: { really: { nested: 'property' } }
|
28 | test: 'data'
|
29 | )
|
30 | district = null
|
31 | async.waterfall [
|
32 | (cb_wf) =>
|
33 | @clever.District.findById '4fd43cc56d11340000000005', cb_wf
|
34 | (_district, cb_wf) =>
|
35 | district = _district
|
36 | assert (district instanceof @clever.District), "Incorrect type on district object"
|
37 | assert.equal district.get('name'), 'Test District'
|
38 | district.properties cb_wf
|
39 | (properties, cb_wf) ->
|
40 | assert.deepEqual { some: { really: { nested: 'property' } } }, properties
|
41 | district.properties { test: 'data' }, cb_wf
|
42 | (properties, cb_wf) ->
|
43 | assert.deepEqual { test: 'data', some: { really: { nested: 'property' } } }, properties
|
44 | cb_wf()
|
45 | ], done
|
46 |
|
47 | it 'checks response codes on properties', (done) ->
|
48 | scope = nock('https://api.clever.com')
|
49 | .get('/v1.1/districts/1212121/properties')
|
50 | .reply(504, {error: 'trolling'})
|
51 | district = new @clever.District { name: 'Test', id: '1212121' }
|
52 | district.properties (err, props) ->
|
53 | assert not props, "found properties"
|
54 | assert err, "didn't find an error"
|
55 | assert.equal err.message, "received statusCode 504 instead of 200"
|
56 | scope.done()
|
57 | done()
|