-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
redisstore: Delete endpoints for related links and tags for samples a…
…nd aspects (#293) * delete rlinks of sample added tests for aspect tag delete delete aspect rlinks tests * changes based on annys comment
- Loading branch information
1 parent
4a64237
commit 5c75891
Showing
7 changed files
with
450 additions
and
14 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
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,128 @@ | ||
/** | ||
* Copyright (c) 2017, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
/** | ||
* tests/cache/models/aspects/deleteRelatedLinks.js | ||
*/ | ||
'use strict'; // eslint-disable-line strict | ||
|
||
const supertest = require('supertest'); | ||
const api = supertest(require('../../../../index').app); | ||
const constants = require('../../../../api/v1/constants'); | ||
const tu = require('../../../testUtils'); | ||
const rtu = require('../redisTestUtil'); | ||
const expect = require('chai').expect; | ||
const Aspect = tu.db.Aspect; | ||
const allDeletePath = '/v1/aspects/{key}/relatedLinks'; | ||
const oneDeletePath = '/v1/aspects/{key}/relatedLinks/{akey}'; | ||
const redisOps = require('../../../../cache/redisOps'); | ||
const objectType = require('../../../../cache/sampleStore') | ||
.constants.objectType; | ||
const samstoinit = rtu.samstoinit; | ||
const ZERO = 0; | ||
const ONE = 1; | ||
|
||
describe('api: aspects: DELETE RelatedLinks', () => { | ||
let token; | ||
let i; | ||
let name; | ||
|
||
const n = { | ||
name: `${tu.namePrefix}ASPECTNAME`, | ||
timeout: '110s', | ||
relatedLinks: [ | ||
{ name: 'rlink0', url: 'https://samples.com' }, | ||
{ name: 'rlink1', url: 'https://samples.com' }, | ||
], | ||
isPublished: true, | ||
}; | ||
|
||
before((done) => { | ||
tu.toggleOverride('enableRedisSampleStore', true); | ||
tu.createToken() | ||
.then((returnedToken) => { | ||
token = returnedToken; | ||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
|
||
beforeEach((done) => { | ||
Aspect.create(n) | ||
.then((asp) => { | ||
i = asp.id; | ||
name = asp.name; | ||
return samstoinit.eradicate(); | ||
}) | ||
.then(() => samstoinit.init()) | ||
.then(() => done()) | ||
.catch(done); | ||
}); | ||
afterEach(rtu.forceDelete); | ||
after(() => tu.toggleOverride('enableRedisSampleStore', false)); | ||
|
||
it('delete all related links', (done) => { | ||
api.delete(allDeletePath.replace('{key}', i)) | ||
.set('Authorization', token) | ||
.expect(constants.httpStatus.OK) | ||
.end((err, res) => { | ||
if (err) { | ||
done(err); | ||
} | ||
|
||
expect(res.body.relatedLinks).to.have.length(ZERO); | ||
redisOps.getHashPromise(objectType.aspect, n.name) | ||
.then((aspect) => { | ||
expect(JSON.parse(aspect.relatedLinks)).to.have.length(ZERO); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('delete one relatedLink', (done) => { | ||
api.delete(oneDeletePath.replace('{key}', i).replace('{akey}', 'rlink0')) | ||
.set('Authorization', token) | ||
.expect(constants.httpStatus.OK) | ||
.end((err, res) => { | ||
if (err) { | ||
done(err); | ||
} | ||
|
||
expect(res.body.relatedLinks).to.have.length(ONE); | ||
expect(res.body.relatedLinks).to.have.deep.property('[0].name', 'rlink1'); | ||
redisOps.getHashPromise(objectType.aspect, n.name) | ||
.then((aspect) => { | ||
const rlinks = JSON.parse(aspect.relatedLinks); | ||
expect(rlinks).to.have.length(ONE); | ||
expect(rlinks).to.have.deep.property('[0].name', 'rlink1'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('delete related link by name', (done) => { | ||
api.delete(oneDeletePath.replace('{key}', name).replace('{akey}', 'rlink0')) | ||
.set('Authorization', token) | ||
.expect(constants.httpStatus.OK) | ||
.end((err, res) => { | ||
if (err) { | ||
done(err); | ||
} | ||
|
||
expect(res.body.relatedLinks).to.have.length(ONE); | ||
expect(res.body.relatedLinks).to.have.deep.property('[0].name', 'rlink1'); | ||
redisOps.getHashPromise(objectType.aspect, n.name) | ||
.then((aspect) => { | ||
const rlinks = JSON.parse(aspect.relatedLinks); | ||
expect(rlinks).to.have.length(ONE); | ||
expect(rlinks).to.have.deep.property('[0].name', 'rlink1'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
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,141 @@ | ||
/** | ||
* Copyright (c) 2017, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
/** | ||
* tests/cache/models/aspects/deleteTags.js | ||
*/ | ||
'use strict'; // eslint-disable-line strict | ||
|
||
const supertest = require('supertest'); | ||
const api = supertest(require('../../../../index').app); | ||
const constants = require('../../../../api/v1/constants'); | ||
const tu = require('../../../testUtils'); | ||
const rtu = require('../redisTestUtil'); | ||
const expect = require('chai').expect; | ||
const Aspect = tu.db.Aspect; | ||
const allDeletePath = '/v1/aspects/{key}/tags'; | ||
const oneDeletePath = '/v1/aspects/{key}/tags/{akey}'; | ||
const redisOps = require('../../../../cache/redisOps'); | ||
const objectType = require('../../../../cache/sampleStore') | ||
.constants.objectType; | ||
const samstoinit = rtu.samstoinit; | ||
|
||
describe(`api: redisStore: aspects: DELETE tags`, () => { | ||
let token; | ||
let aspId; | ||
let aspName; | ||
const tag0 = 'tag0'; | ||
|
||
const n = { | ||
name: `${tu.namePrefix}ASPECTNAME`, | ||
timeout: '110s', | ||
tags: ['tag0', 'tag1'], | ||
isPublished: true, | ||
}; | ||
|
||
before((done) => { | ||
tu.toggleOverride('enableRedisSampleStore', true); | ||
tu.createToken() | ||
.then((returnedToken) => { | ||
token = returnedToken; | ||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
|
||
beforeEach((done) => { | ||
Aspect.create(n) | ||
.then((asp) => { | ||
aspId = asp.id; | ||
aspName = asp.name; | ||
return samstoinit.eradicate(); | ||
}) | ||
.then(() => samstoinit.init()) | ||
.then(() => done()) | ||
.catch(done); | ||
}); | ||
afterEach(rtu.forceDelete); | ||
after(() => tu.toggleOverride('enableRedisSampleStore', false)); | ||
|
||
it('delete all tags', (done) => { | ||
api.delete(allDeletePath.replace('{key}', aspId)) | ||
.set('Authorization', token) | ||
.expect(constants.httpStatus.OK) | ||
.end((err, res) => { | ||
if (err) { | ||
done(err); | ||
} | ||
expect(res.body.tags).to.have.length(0); | ||
redisOps.getHashPromise(objectType.aspect, n.name) | ||
.then((aspect) => { | ||
expect(JSON.parse(aspect.tags)).to.have.length(0); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('delete one tag', (done) => { | ||
api.delete(oneDeletePath.replace('{key}', aspId).replace('{akey}', tag0)) | ||
.set('Authorization', token) | ||
.expect(constants.httpStatus.OK) | ||
.end((err, res) => { | ||
if (err) { | ||
done(err); | ||
} | ||
expect(res.body.tags).to.have.length(1); | ||
expect(res.body.tags).to.have.members(['tag1']); | ||
redisOps.getHashPromise(objectType.aspect, n.name) | ||
.then((aspect) => { | ||
const tags = JSON.parse(aspect.tags); | ||
expect(tags).to.have.length(1); | ||
expect(tags).to.have.members(['tag1']); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('delete tag by name', (done) => { | ||
api.delete(oneDeletePath.replace('{key}', aspName).replace('{akey}', tag0)) | ||
.set('Authorization', token) | ||
.expect(constants.httpStatus.OK) | ||
.end((err, res) => { | ||
if (err) { | ||
done(err); | ||
} | ||
expect(res.body.tags).to.have.length(1); | ||
expect(res.body.tags).to.have.members(['tag1']); | ||
redisOps.getHashPromise(objectType.aspect, n.name) | ||
.then((aspect) => { | ||
const tags = JSON.parse(aspect.tags); | ||
expect(tags).to.have.length(1); | ||
expect(tags).to.have.members(['tag1']); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('no error if tag not found, no update on tags', (done) => { | ||
api.delete(oneDeletePath.replace('{key}', aspId).replace('{akey}', 'x')) | ||
.set('Authorization', token) | ||
.expect(constants.httpStatus.OK) | ||
.end((err, res) => { | ||
if (err) { | ||
done(err); | ||
} | ||
expect(res.body.tags).to.have.length(2); | ||
expect(res.body.tags).to.have.members(['tag1', 'tag0']); | ||
redisOps.getHashPromise(objectType.aspect, n.name) | ||
.then((aspect) => { | ||
const tags = JSON.parse(aspect.tags); | ||
expect(tags).to.have.length(2); | ||
expect(tags).to.have.members(['tag1', 'tag0']); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.