-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add mechanism to pass callback to @kfarranger-server
- Loading branch information
1 parent
57f00a8
commit be1445c
Showing
3 changed files
with
79 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { sqsQueueUrl } from '../env'; | ||
|
||
export const postProcessSaveSet = (sqs) => async data => { | ||
const params = { MessageBody: JSON.stringify(data), QueueUrl: sqsQueueUrl }; | ||
return sqs.sendMessage(params).promise(); | ||
}; |
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,57 @@ | ||
import AWSMock from 'aws-sdk-mock'; | ||
import AWS from 'aws-sdk'; | ||
import { postProcessSaveSet } from './saveSet'; | ||
import SQS from 'aws-sdk/clients/sqs'; | ||
import { describe, it, beforeEach, afterEach } from 'mocha'; | ||
import { expect } from 'chai'; | ||
|
||
const mockSaveSetData = { | ||
setId: '123xyyz', | ||
createdAt: Date.now(), | ||
ids: ['id1', '1d2'], | ||
size: 2, | ||
sqon: { | ||
op: 'and', | ||
content: [ | ||
{ | ||
op: 'in', | ||
content: { | ||
field: 'observed_phenotype.name', | ||
value: ['Abnormality of the cardiovascular system (HP:0001626)'], | ||
}, | ||
}, | ||
], | ||
}, | ||
type: 'participant', | ||
userId: 'd1c3f78f-a68f-46c4-a44f-9d1249d6337e', | ||
path: 'kf_id', | ||
sort: [], | ||
tag: 'test', | ||
}; | ||
|
||
describe('Test case for SQS SendMessage', () => { | ||
beforeEach(() => { | ||
AWSMock.setSDKInstance(AWS); | ||
}); | ||
|
||
afterEach(() => { | ||
AWSMock.restore(); | ||
}); | ||
|
||
it('should return a successful response', async () => { | ||
AWSMock.mock('SQS', 'sendMessage', () => Promise.resolve({ MessageId: '123' })); | ||
const sqs = new AWS.SQS({ apiVersion: '2012-11-05' }); | ||
const res = await postProcessSaveSet(sqs)(mockSaveSetData); | ||
expect(res.MessageId).to.equal('123'); | ||
}); | ||
|
||
it('should throw when the queue does not respond', async () => { | ||
AWSMock.mock('SQS', 'sendMessage', () => Promise.reject('could not send data to queue')); | ||
const sqs = new AWS.SQS({ apiVersion: '2012-11-05' }); | ||
try { | ||
await postProcessSaveSet(sqs)(mockSaveSetData); | ||
} catch (err) { | ||
expect(err).to.eql('could not send data to queue'); | ||
} | ||
}); | ||
}); |