digitalocean
Version:
nodejs wrapper for digitalocean v2 api
272 lines (223 loc) • 7.15 kB
JavaScript
;
var expect = require('chai').expect;
var testUtils = require('../testUtils');
var digitalocean = require('../../lib/digitalocean');
var token = testUtils.getUserDigitalOceanToken();
var client = digitalocean.client(token);
describe('tag endpoints', function() {
describe('list', function() {
var data = {
"tags": [
{
"name": "extra-awesome",
"resources": {
"droplets": {
"count": 0,
"last_tagged": null
}
}
},
{
"name": "foo",
"resources": {
"droplets": {
"count": 0,
"last_tagged": null
}
}
}
],
"meta": {
"total": 1
}
};
it('returns tags', function() {
testUtils.api.get('/v2/tags').reply(200, JSON.stringify(data));
client.tags.list(function(err, tags, headers) {
expect(tags).to.shallowDeepEqual(data.tags);
});
});
it('returns tags at page', function() {
testUtils.api.get('/v2/tags?page=2').reply(200, JSON.stringify(data));
client.tags.list(2, function(err, tags, headers) {
expect(tags).to.shallowDeepEqual(data.tags);
});
});
it('returns tags at page with length', function() {
testUtils.api.get('/v2/tags?page=2&per_page=1').reply(200, JSON.stringify(data));
client.tags.list(2, 1, function(err, tags, headers) {
expect(tags).to.shallowDeepEqual(data.tags);
});
});
it('returns tags with a query object', function() {
testUtils.api.get('/v2/tags?page=2&per_page=1').reply(200, JSON.stringify(data));
client.tags.list({ page: 2, per_page: 1 }, function(err, tags, headers) {
expect(tags).to.shallowDeepEqual(data.tags);
});
});
it('returns a promisable', function(done) {
testUtils.api.get('/v2/tags').reply(200, JSON.stringify(data));
client.tags.list().then(function(tags) {
expect(tags).to.shallowDeepEqual(data.tags);
done();
}).catch(function(err) {
done(err);
});
});
it('returns a promisable with a query object', function(done) {
testUtils.api.get('/v2/tags?page=2&per_page=1').reply(200, JSON.stringify(data));
client.tags.list({ page: 2, per_page: 1 }).then(function(tags) {
expect(tags).to.shallowDeepEqual(data.tags);
done();
}).catch(function(err) {
done(err);
});
});
});
describe('create', function() {
var data = {
"tag": {
"name": "foo",
"resources": {
"droplets": {
"count": 0,
"last_tagged": null
}
}
}
};
var attributes = {
"name": "foo"
};
it('creates the tag', function() {
testUtils.api.post('/v2/tags', attributes).reply(201, data);
client.tags.create(attributes, function(err, tag, headers) {
expect(tag).to.shallowDeepEqual(data.tag);
});
});
it('returns a promisable', function(done) {
testUtils.api.post('/v2/tags', attributes).reply(201, data);
client.tags.create(attributes).then(function(tag) {
expect(tag).to.shallowDeepEqual(data.tag);
done();
}).catch(function(err) {
done(err);
});
});
});
describe('get', function() {
var data = {
"tag": {
"name": "foo",
"resources": {
"droplets": {
"count": 0,
"last_tagged": null
}
}
}
};
it('returns the tag', function() {
testUtils.api.get('/v2/tags/foo').reply(200, JSON.stringify(data));
client.tags.get('foo', function(err, tag, headers) {
expect(tag).to.shallowDeepEqual(data.tag);
});
});
it('escapes the name', function() {
testUtils.api.get('/v2/tags/foo%2Fbar').reply(200, JSON.stringify(data));
client.tags.get('foo/bar', function(err, tag, headers) {
expect(tag).to.shallowDeepEqual(data.tag);
});
});
it('returns a promisable', function(done) {
testUtils.api.get('/v2/tags/foo').reply(200, JSON.stringify(data));
client.tags.get('foo').then(function(tag) {
expect(tag).to.shallowDeepEqual(data.tag);
done();
}).catch(function(err) {
done(err);
});
});
});
describe('tag', function() {
var resources = [
{
"resource_id": "9569411",
"resource_type": "droplet"
}
];
it('tags the resources', function() {
testUtils.api.post('/v2/tags/foo/resources', { resources: resources }).reply(204, '');
client.tags.tag('foo', resources, function(err, tag, headers) {
expect(err).to.be.null;
});
});
it('escapes the name', function() {
testUtils.api.post('/v2/tags/foo%2Fbar/resources', { resources: resources }).reply(204, '');
client.tags.tag('foo/bar', resources, function(err, tag, headers) {
expect(err).to.be.null;
});
});
it('returns a promisable', function(done) {
testUtils.api.post('/v2/tags/foo/resources', { resources: resources }).reply(204, '');
client.tags.tag('foo', resources).then(function(result) {
expect(result).to.be.present;
done();
}).catch(function(err) {
done(err);
});
});
});
describe('untag', function() {
var resources = [
{
"resource_id": "9569411",
"resource_type": "droplet"
}
];
it('untags the resources', function() {
testUtils.api.delete('/v2/tags/foo/resources', { resources: resources }).reply(204, '');
client.tags.untag('foo', resources, function(err, tag, headers) {
expect(err).to.be.null;
});
});
it('escapes the name', function() {
testUtils.api.delete('/v2/tags/foo%2Fbar/resources', { resources: resources }).reply(204, '');
client.tags.untag('foo/bar', resources, function(err, tag, headers) {
expect(err).to.be.null;
});
});
it('returns a promisable', function(done) {
testUtils.api.delete('/v2/tags/foo/resources', { resources: resources }).reply(204, '');
client.tags.untag('foo', resources).then(function(result) {
expect(result).to.be.present;
done();
}).catch(function(err) {
done(err);
});
});
});
describe('delete', function() {
it('deletes the tag', function() {
testUtils.api.delete('/v2/tags/foo').reply(204, '');
client.tags.delete('foo', function(err) {
expect(err).to.be.null;
});
});
it('escapes the name', function() {
testUtils.api.delete('/v2/tags/foo%2Fbar').reply(204, '');
client.tags.delete('foo/bar', function(err) {
expect(err).to.be.null;
});
});
it('returns a promisable', function(done) {
testUtils.api.delete('/v2/tags/foo').reply(204, '');
client.tags.delete('foo').then(function(tag) {
expect(tag.name).to.be.undefined;
done();
}).catch(function(err) {
done(err);
});
});
});
});