describe('#value()', () => { it('should be a method of the model', () => { should(data.users) .have.property('value') .which.is.Function() }) it('should be able to take column value of single record', () => { api .get(`/v3/instances/${instanceName}/classes/users/objects/`) .query({page_size: 1, limit: 1}) .reply(200, {objects: [{name: 'John', id: 2}]}) return data.users.value('name').should.become('John') }) })
it('should load next page', () => { api .get(`/v3/instances/${instanceName}/classes/users/objects/`) .query({page_size: 2, limit: 2}) // eslint-disable-line camelcase .reply(200, { objects: [{id: 1}], next: `/v3/instances/${instanceName}/classes/users/objects/?page_size=2&last_pk=1` }) .get(`/v3/instances/${instanceName}/classes/users/objects/`) .query({page_size: 2, last_pk: 1, limit: 2}) // eslint-disable-line camelcase .reply(200, {objects: [{id: 2}], next: null}) return data.users .take(2) .list() .should.become([{id: 1}, {id: 2}]) })
it('should resolve custom types', () => { const date = new Date().toISOString() api .get(`/v3/instances/${instanceName}/classes/users/objects/`) .query({page_size: 500}) // eslint-disable-line camelcase .reply(200, { objects: [ { created_at: { value: date, type: 'datetime' } } ] }) return data.users.list().should.become([{created_at: date}]) })
describe('Promise request', () => { beforeEach(() => { nock(domain) .get(okPath) .reply(200, okText) .post(okPath) .reply(200, okText); ifttt = new IFTTT(testKey); }); afterEach(() => { nock.cleanAll(); ifttt = null; }); it('GET using event string OK with Promise', () => expect(ifttt.request(testEvent)).to.become(okText)); it('GET using event object OK with Promise', () => expect(ifttt.request({ event: testEvent })).to.become(okText)); it('POST using event object OK with Promise', () => expect(ifttt.request({ method: 'POST', event: testEvent })).to.become(okText)); });
describe('User', () => { const instanceName = 'testInstance' let api: nock.Scope let users: UserClass beforeEach(() => { const server = new Server({ token: 'testKey', instanceName }) users = server.users api = nock(`https://${process.env.SYNCANO_HOST || 'api.syncano.io'}`) }) describe('#list', () => { it('should list users', () => { api .get(`/v3/instances/${instanceName}/users/`) .query({ page_size: 500 }) .reply(200, {objects: [{id: 1}, {id: 2}]}) return users.list().should.become([{id: 1}, {id: 2}]) }) }) })
return response; }, waitOnCertification); return expect(subject).to.become({ status: 204, etag: undefined,
.reply(200, {objects: [{name: 'John Doe', id: 7}]}) return data.users.find(7).should.become({name: 'John Doe', id: 7}) }) .should.become([{name: 'John Doe', id: 7}, {name: 'Jane Doe', id: 8}]) }) .reply(200, {objects: [], next: null}) return data.users.find(5).should.become(null) }) .reply(200, {objects: [], next: null}) return data.users.find([7, 8]).should.become([]) }) })
describe('#min()', () => { it('should be a method of the model', () => { should(data.posts) .have.property('min') .which.is.Function() }) it('should return minimal value for given column', () => { api .get(`/v3/instances/${instanceName}/classes/posts/objects/`) .query({page_size: 1, limit: 1, order_by: 'likes'}) // eslint-disable-line camelcase .reply(200, {objects: [{likes: 12, id: 3}]}) return data.posts.min('likes').should.become(12) }) it('should return null when there are no records in given class', () => { api .get(`/v3/instances/${instanceName}/classes/posts/objects/`) .query({page_size: 1, limit: 1, order_by: 'likes'}) // eslint-disable-line camelcase .reply(200, {objects: []}) return data.posts.min('likes').should.become(null) }) })
describe('#firstOrFail()', () => { it('should be a method of the model', () => { should(data.users) .have.property('firstOrFail') .which.is.Function() }) it('should be able to fetch single object', () => { api .get(`/v3/instances/${instanceName}/classes/users/objects/`) .query({page_size: 1, limit: 1}) // eslint-disable-line camelcase .reply(200, {objects: [{name: 'John Doe', id: 3}]}) return data.users.firstOrFail().should.become({name: 'John Doe', id: 3}) }) it('should throw error when object was not found', async () => { api .get(`/v3/instances/${instanceName}/classes/users/objects/`) .query({page_size: 1, limit: 1}) // eslint-disable-line camelcase .reply(404) return data.users.firstOrFail().should.be.rejected }) })
describe('#count()', () => { it('should be a method of the model', () => { should(data.posts) .have.property('count') .which.is.Function() }) it('should number of records', () => { api .get(`/v2/instances/${instanceName}/classes/users/objects/`) .query({page_size: 0, include_count: 1}) // eslint-disable-line camelcase .reply(200, {objects_count: 2}) return data.users.count().should.become(2) }) })
describe('#first()', () => { it('should be a method of the model', () => { should(data.users) .have.property('first') .which.is.Function() }) it('should be able to fetch single object', () => { api .get(`/v3/instances/${instanceName}/classes/users/objects/`) .query({page_size: 1, limit: 1}) // eslint-disable-line camelcase .reply(200, {objects: [{name: 'John Doe', id: 3}]}) return data.users.first().should.become({name: 'John Doe', id: 3}) }) it('should return null when object was not found', () => { api .get(`/v3/instances/${instanceName}/classes/users/objects/`) .query({page_size: 1, limit: 1}) // eslint-disable-line camelcase .reply(200, {objects: []}) return data.users.first().should.become(null) }) })
describe('#pluck()', () => { it('should be a method of the model', () => { should(data.users) .have.property('pluck') .which.is.Function() }) it('should be able to take column values', () => { api .get(`/v3/instances/${instanceName}/classes/users/objects/`) .query({ page_size: 500 }) .reply(200, {objects: [{name: 'John', id: 2}, {name: 'Jane', id: 3}]}) return data.users.pluck('name').should.become(['John', 'Jane']) }) })