Skip to content

Commit b9a58d9

Browse files
authored
Merge pull request #1815 from CVEProject/dr_1663
Resolves issue #1663, Resolve inconsistent parameters and query target UUID when fetching review history conversations.
2 parents 3a01de6 + 5b9d5b9 commit b9a58d9

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

src/repositories/conversationRepository.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ class ConversationRepository extends BaseRepository {
3636
}
3737

3838
async getAllByTargetUUID (targetUUID, isSecretariat, options = {}) {
39+
const findOptions = {}
40+
if (options.session) {
41+
findOptions.session = options.session
42+
}
3943
const conversations = await ConversationModel.find({ target_uuid: targetUUID }, null, {
40-
...options,
44+
...findOptions,
4145
sort: {
4246
posted_at: 1,
4347
UUID: 1

src/repositories/reviewObjectRepository.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class ReviewObjectRepository extends BaseRepository {
245245
const conversationRepository = new ConversationRepository()
246246

247247
for (const review of data.reviewObjects) {
248-
let conversations = await conversationRepository.getAllByTargetUUID(review.uuid, isSecretariat, options)
248+
let conversations = await conversationRepository.getAllByTargetUUID(review.target_object_uuid, isSecretariat)
249249

250250
// Filter conversations based on user role
251251
if (conversations && conversations.length) {

test/integration-tests/review-object/reviewObjectTest.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,27 @@ describe('Review Object Controller Integration Tests', () => {
184184
})
185185

186186
it('Retrieves review history with conversations included', async () => {
187+
// 1. Post a conversation message to the organization target UUID
188+
const msgRes = await chai
189+
.request(app)
190+
.post(`/api/conversation/target/${orgUUID}`)
191+
.set({ ...constants.headers })
192+
.send({ body: 'Test comment on org history', visibility: 'public' })
193+
expect(msgRes).to.have.status(200)
194+
195+
// 2. Fetch the review history with conversations included
187196
const res = await chai
188197
.request(app)
189198
.get(`/api/review/org/${constants.testRegistryOrg2.short_name}/reviews?include_conversations=true`)
190199
.set({ ...constants.headers })
191200
expect(res).to.have.status(200)
192201
expect(res.body).to.have.property('reviewObjects')
193-
if (res.body.reviewObjects.length > 0) {
194-
expect(res.body.reviewObjects[0]).to.have.property('conversation')
195-
}
202+
expect(res.body.reviewObjects).to.be.an('array')
203+
expect(res.body.reviewObjects.length).to.be.greaterThan(0)
204+
expect(res.body.reviewObjects[0]).to.have.property('conversation')
205+
expect(res.body.reviewObjects[0].conversation).to.be.an('array')
206+
expect(res.body.reviewObjects[0].conversation.length).to.be.greaterThan(0)
207+
expect(res.body.reviewObjects[0].conversation[0]).to.have.property('body', 'Test comment on org history')
196208
})
197209

198210
it('Nonsecretariat user can update an organization, review object gets created', async () => {

0 commit comments

Comments
 (0)