Skip to content

Commit

Permalink
Merge branch 'master' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronschachter committed Oct 25, 2018
2 parents 25529ab + 16f118f commit dde94a0
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 25 deletions.
5 changes: 0 additions & 5 deletions documentation/endpoints/topics.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ curl http://localhost:5000/v1/topics?skip=5
"topic": {}
}
},
"triggers": []
},
{
"id": "2X4r3fZrTGA2mGemowgiEI",
Expand Down Expand Up @@ -118,7 +117,6 @@ curl http://localhost:5000/v1/topics?skip=5
"topic": {}
}
},
"triggers": [],
},
{
"id": "3peS2Oye08o6OwUMAEcS2c",
Expand All @@ -144,9 +142,6 @@ curl http://localhost:5000/v1/topics?skip=5
},
...
},
"triggers": [
"mascot",
]
},
...
],
Expand Down
8 changes: 0 additions & 8 deletions lib/middleware/topics/index/topics-get.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ module.exports = function getTopics() {
.then((fetchTopicResult) => {
req.data = fetchTopicResult.data;
req.meta = fetchTopicResult.meta;
const promises = req.data.map(topic => helpers.defaultTopicTrigger.getByTopicId(topic.id));
return Promise.all(promises);
})
.then((defaultTopicTriggersByTopic) => {
defaultTopicTriggersByTopic.forEach((result, index) => {
req.data[index].triggers = helpers.defaultTopicTrigger
.getTriggersFromDefaultTopicTriggers(result);
});
return helpers.response.sendIndexData(res, req.data, req.meta);
})
.catch(err => helpers.sendErrorResponse(res, err));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gambit-campaigns",
"version": "5.14.2",
"version": "5.14.3",
"description": "The DoSomething.org chatbot service for campaigns and their activity.",
"license": "MIT",
"repository": {
Expand Down
12 changes: 1 addition & 11 deletions test/lib/middleware/topics/index/topics-get.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,16 @@ test.afterEach((t) => {
test('getTopics should send helpers.topic.fetch result', async (t) => {
const next = sinon.stub();
const middleware = getTopics();
const triggers = [stubs.getRandomWord()];
const firstTopic = topicFactory.getValidTopic();
const secondTopic = topicFactory.getValidTopic();
const topics = [firstTopic, secondTopic];
const topics = [topicFactory.getValidTopic(), topicFactory.getValidTopic()];
const fetchResult = stubs.contentful.getFetchByContentTypesResultWithArray(topics);
sandbox.stub(helpers.topic, 'fetch')
.returns(Promise.resolve(fetchResult));
sandbox.stub(helpers.defaultTopicTrigger, 'getByTopicId')
.returns(Promise.resolve(fetchResult));
sandbox.stub(helpers.defaultTopicTrigger, 'getTriggersFromDefaultTopicTriggers')
.returns(triggers);
const queryParams = { skip: 20 };
t.context.req.query = queryParams;

// test
await middleware(t.context.req, t.context.res, next);
helpers.topic.fetch.should.have.been.calledWith(queryParams);
helpers.defaultTopicTrigger.getByTopicId.should.have.been.calledWith(firstTopic.id);
helpers.defaultTopicTrigger.getByTopicId.should.have.been.calledWith(secondTopic.id);

helpers.response.sendIndexData
.should.have.been.calledWith(t.context.res, fetchResult.data, fetchResult.meta);
helpers.sendErrorResponse.should.not.have.been.called;
Expand Down

0 comments on commit dde94a0

Please sign in to comment.