-
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.
Merge pull request #147 from kids-first/2477-save-set-callbacks
2477 save set callbacks
- Loading branch information
Showing
8 changed files
with
2,074 additions
and
1,137 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ PROJECT_ID= | |
ES_HOST= | ||
ES_FILE_INDEX= | ||
ES_FILE_TYPE= | ||
SQS_QUEUE_URL= | ||
|
||
PYTHON_PATH= | ||
SURVIVAL_PY_FILE= |
Large diffs are not rendered by default.
Oops, something went wrong.
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,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'); | ||
} | ||
}); | ||
}); |