diff --git a/README.md b/README.md index e1a34bed..4971e817 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,7 @@ async function handler() { - [.dataCenters()](#dataCenters) - [.publicIpList()](#publicIpList) - [.edgeCheck(url)](#edgeCheck) + - [.serviceList()](#serviceList) - [.versionList()](#versionList) - [.domainList(version)](#domainList) @@ -407,6 +408,27 @@ instance.edgeCheck('api.example.com') **Param**: url => `string` **Return**: schema => `promise` + + +### [.serviceList()](https://docs.fastly.com/api/config#service_74d98f7e5d018256e44d1cf820388ef8) + +*List all services.* + +**Example**: + +```javascript +instance.serviceList() + .then(res => { + console.log(res.data); + }) + .catch(err => { + console.log(err.message); + }); +``` + +**Kind**: method +**Return**: schema => `promise` + ### [.versionList()](https://docs.fastly.com/api/config#version_dfde9093f4eb0aa2497bbfd1d9415987) diff --git a/src/index.js b/src/index.js index a51e5100..0fb7b4bb 100644 --- a/src/index.js +++ b/src/index.js @@ -126,6 +126,17 @@ class Fastly { return this.request.get(`/content/edge_check?url=${url}`); } + /** + * List all services. + * + * @name serviceList + * @method + * @return {Promise} + */ + serviceList() { + return this.request.get(`/service`); + } + /** * List the versions for a particular service. * diff --git a/test/response/serviceList.response.js b/test/response/serviceList.response.js new file mode 100644 index 00000000..77dd0b03 --- /dev/null +++ b/test/response/serviceList.response.js @@ -0,0 +1,27 @@ +'use strict'; + +module.exports.serviceList = [ + { + 'comment': '', + 'customer_id': 'x4xCwxxJxGCx123Rx5xTx', + 'id': 'SU1Z0isxPaozGVKXdv0eY', + 'name': 'test service', + 'version': 1, + 'versions': [ + { + 'active': null, + 'comment': '', + 'created_at': '2016-04-27T19:40:49', + 'deleted_at': null, + 'deployed': null, + 'locked': '1', + 'number': '1', + 'service': 'SU1Z0isxPaozGVKXdv0eY', + 'service_id': 'SU1Z0isxPaozGVKXdv0eY', + 'staging': null, + 'testing': null, + 'updated_at': '2016-05-09T16:27:00' + } + ] + } +]; diff --git a/test/serviceList.test.js b/test/serviceList.test.js new file mode 100644 index 00000000..37fddb65 --- /dev/null +++ b/test/serviceList.test.js @@ -0,0 +1,44 @@ +'use strict'; + +const nock = require('nock'); +const expect = require('expect'); +const config = require('../src/config'); +const fastlyPromises = require('../src/index'); +const response = require('./response/serviceList.response'); + +describe('#serviceList', () => { + const fastly = fastlyPromises('923b6bd5266a7f932e41962755bd4254', 'SU1Z0isxPaozGVKXdv0eY'); + let res; + + nock(config.mainEntryPoint) + .get('/service') + .reply(200, response.serviceList); + + before(async () => { + res = await fastly.serviceList(); + }); + + it('response should be a status 200', () => { + expect(res.status).toBe(200); + }); + + it('response body should exist', () => { + expect(res.data).toExist(); + }); + + it('response body should be an array', () => { + expect(Array.isArray(res.data)).toBe(true); + }); + + it('response body should be an array of objects', () => { + res.data.forEach(item => { + expect(item).toBeA('object'); + }); + }); + + it('response body items should have comment, customer_id, id, name, version, and versions properties', () => { + res.data.forEach(item => { + expect(item).toIncludeKeys(['comment', 'customer_id', 'id', 'name', 'version', 'versions']); + }); + }); +});