forked from philippschulte/fastly-promises
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fastly): Add CRUD support for Dictionary Items
Adds support for listing, reading, creating, updating, and deleting items from edge dictionaries. The best way to use this feature is through the `writeDictItem(version, name, key, value)` method Fixes #6
- Loading branch information
Showing
8 changed files
with
666 additions
and
0 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,60 @@ | ||
'use strict'; | ||
|
||
/* eslint-env mocha */ | ||
|
||
const nock = require('nock'); | ||
const expect = require('expect'); | ||
const config = require('../src/config'); | ||
const fastlyPromises = require('../src/index'); | ||
const response = require('./response/dictitem.response'); | ||
|
||
describe('#readDictItems', () => { | ||
const fastly = fastlyPromises('923b6bd5266a7f932e41962755bd4254', 'SU1Z0isxPaozGVKXdv0eY'); | ||
let res; | ||
|
||
nock(config.mainEntryPoint) | ||
// get the dictionary first | ||
.get('/service/SU1Z0isxPaozGVKXdv0eY/version/1/dictionary/my_dictionary') | ||
.reply(200, response.dict.get) | ||
// list | ||
.get('/service/SU1Z0isxPaozGVKXdv0eY/dictionary/5clCytcTJrnvPi8wjqPH0q/items') | ||
.reply(200, response.item.list); | ||
|
||
before(async () => { | ||
res = await fastly.readDictItems(1, 'my_dictionary'); | ||
}); | ||
|
||
it('response should be a status 200', () => { | ||
expect(res.status).toBe(200); | ||
}); | ||
|
||
it('response body should exist', () => { | ||
expect(res.data).toBeTruthy(); | ||
}); | ||
|
||
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(typeof item).toBe('object'); | ||
}); | ||
}); | ||
|
||
it('response body should contain all properties', () => { | ||
res.data.forEach((item) => { | ||
[ | ||
'dictionary_id', | ||
'service_id', | ||
'item_key', | ||
'item_value', | ||
'created_at', | ||
'deleted_at', | ||
'updated_at', | ||
].forEach((e) => { | ||
expect(Object.keys(item)).toContain(e); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.