Skip to content

Commit

Permalink
feat(serviceList): Add serviceList class method
Browse files Browse the repository at this point in the history
Add serviceList class method to list all the services of the account
  • Loading branch information
philippschulte committed Sep 3, 2017
1 parent f5d2adc commit 990522c
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ async function handler() {
- [.dataCenters()](#dataCenters)
- [.publicIpList()](#publicIpList)
- [.edgeCheck(url)](#edgeCheck)
- [.serviceList()](#serviceList)
- [.versionList()](#versionList)
- [.domainList(version)](#domainList)

Expand Down Expand Up @@ -407,6 +408,27 @@ instance.edgeCheck('api.example.com')
**Param**: url => `string`
**Return**: schema => `promise`

<a name="serviceList"></a>

### [.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`

<a name="versionList"></a>

### [.versionList()](https://docs.fastly.com/api/config#version_dfde9093f4eb0aa2497bbfd1d9415987)
Expand Down
11 changes: 11 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
27 changes: 27 additions & 0 deletions test/response/serviceList.response.js
Original file line number Diff line number Diff line change
@@ -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'
}
]
}
];
44 changes: 44 additions & 0 deletions test/serviceList.test.js
Original file line number Diff line number Diff line change
@@ -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']);
});
});
});

0 comments on commit 990522c

Please sign in to comment.