-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* etag for keys * Tests added * add etag to reponse header on update * check alias key etag * safe Co-authored-by: Yoav Karako <yoav@soluto.com>
- Loading branch information
Showing
3 changed files
with
130 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
const { expect } = require('chai'); | ||
const client = require('../../utils/client'); | ||
const { pollUntil } = require('../../utils/utils'); | ||
const { createManifestForJPadKey } = require('../../utils/manifest'); | ||
|
||
const keyPath = '@tests/integration/new_key_with_etag'; | ||
const author = { name: 'ellie', email: 'ellie@lou.com' }; | ||
const authorQuery = { 'author.name': author.name, 'author.email': author.email }; | ||
|
||
describe.only('Key etag', () => { | ||
let etag; | ||
it('Create new key', async () => { | ||
await client | ||
.put(`/api/v2/keys/${keyPath}`) | ||
.query(authorQuery) | ||
.send({ | ||
manifest: createManifestForJPadKey(keyPath), | ||
implementation: JSON.stringify({ | ||
partitions: [], | ||
defaultValue: 'test', | ||
valueType: 'string', | ||
rules: [], | ||
}), | ||
}) | ||
.expect(200); | ||
|
||
await pollUntil( | ||
() => client.get(`/api/v2/values/${keyPath}`), | ||
(res) => expect(res.body).to.eql('test'), | ||
); | ||
}); | ||
|
||
it('GET key with Etag', async () => { | ||
await client.get(`/api/v2/keys/${keyPath}`).then((res) => { | ||
etag = res.headers.etag; | ||
}); | ||
expect(etag).to.be.not.undefined; | ||
}); | ||
|
||
it('Update key with right Etag', async () => { | ||
await client | ||
.put(`/api/v2/keys/${keyPath}`) | ||
.query(authorQuery) | ||
.send({ | ||
manifest: createManifestForJPadKey(keyPath), | ||
implementation: JSON.stringify({ | ||
partitions: [], | ||
defaultValue: 'test2', | ||
valueType: 'string', | ||
rules: [], | ||
}), | ||
}) | ||
.set('If-Match', etag) | ||
.expect(200); | ||
|
||
await pollUntil( | ||
() => client.get(`/api/v2/values/${keyPath}`), | ||
(res) => expect(res.body).to.eql('test2'), | ||
); | ||
}); | ||
|
||
it('Update key with wrong Etag', async () => { | ||
await client | ||
.put(`/api/v2/keys/${keyPath}`) | ||
.query(authorQuery) | ||
.send({ | ||
manifest: createManifestForJPadKey(keyPath), | ||
implementation: JSON.stringify({ | ||
partitions: [], | ||
defaultValue: 'test3', | ||
valueType: 'string', | ||
rules: [], | ||
}), | ||
}) | ||
.set('If-Match', etag) | ||
.expect(412); | ||
}); | ||
}); |
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