-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(createSnippet): Add createSnippet class method
Add createSnippet class method to create a snippet for a particular service and version
- Loading branch information
1 parent
563a0b8
commit f59570f
Showing
4 changed files
with
118 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use strict'; | ||
|
||
const nock = require('nock'); | ||
const expect = require('expect'); | ||
const config = require('../src/config'); | ||
const fastlyPromises = require('../src/index'); | ||
const response = require('./response/createSnippet.response'); | ||
|
||
describe('#createSnippet', () => { | ||
const fastly = fastlyPromises('923b6bd5266a7f932e41962755bd4254', 'SU1Z0isxPaozGVKXdv0eY'); | ||
let res; | ||
|
||
nock(config.mainEntryPoint) | ||
.post('/service/SU1Z0isxPaozGVKXdv0eY/version/1/snippet') | ||
.reply(200, response.createSnippet); | ||
|
||
before(async () => { | ||
res = await fastly.createSnippet('1', { name: 'my_snippet', priority: '10', dynamic: '1', type: 'fetch' }); | ||
}); | ||
|
||
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 object', () => { | ||
expect(res.data).toBeA('object'); | ||
}); | ||
|
||
it('response body properties should be created', () => { | ||
expect(res.data.name).toBe('my_snippet'); | ||
expect(res.data.priority).toBe('10'); | ||
expect(res.data.dynamic).toBe('1'); | ||
expect(res.data.type).toBe('fetch'); | ||
}); | ||
|
||
it('response body should contain all properties', () => { | ||
expect(res.data).toIncludeKeys([ | ||
'name', | ||
'priority', | ||
'dynamic', | ||
'content', | ||
'type', | ||
'service_id', | ||
'version', | ||
'deleted_at', | ||
'created_at', | ||
'updated_at', | ||
'id' | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
module.exports.createSnippet = { | ||
'name': 'my_snippet', | ||
'priority': '10', | ||
'dynamic': '1', | ||
'content': null, | ||
'type': 'fetch', | ||
'service_id': 'SU1Z0isxPaozGVKXdv0eY', | ||
'version': '1', | ||
'deleted_at': null, | ||
'created_at': '2018-03-11T00:46:24Z', | ||
'updated_at': '2018-03-11T00:46:24Z', | ||
'id': '62Yd1WfiCBPENLloXfXmlO' | ||
}; |