Skip to content
This repository has been archived by the owner on Jan 4, 2024. It is now read-only.

Commit

Permalink
add sns publish
Browse files Browse the repository at this point in the history
  • Loading branch information
ste-xx committed Jun 4, 2018
1 parent 8dcec1c commit 554be0a
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 25 deletions.
2 changes: 1 addition & 1 deletion deploy_s3.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

mkdir deploy
zip -r deploy/s2t-incoming-not-transcoded-file-eventhandler.zip index.js s3Api.js node_modules/
zip -r deploy/s2t-incoming-not-transcoded-file-eventhandler.zip index.js s3Api.js snsApi.js node_modules/
28 changes: 28 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const test = process.env['MODE'] === 'test';
let s3Api = test ? require('./test/s3ApiMock.js') : require('./s3Api.js');
let snsApi = test ? require('./test/snsApiMock.js') : require('./snsApi.js');

exports.handler = async (event) => {

Expand Down Expand Up @@ -33,6 +34,33 @@ exports.handler = async (event) => {
Key: key
});

await snsApi.publish({
Message: 'placeholder',
MessageAttributes: {
bucket: {
DataType: 'String',
StringValue: bucketName
},
key: {
DataType: 'String',
StringValue: key
},
"transcribe-provider": {
DataType: 'String',
StringValue: provider
},
pid: {
DataType: 'String',
StringValue: pid
},
"api-key-id": {
DataType: 'String',
StringValue: apiKeyId
},
},
TopicArn: process.env['TOPIC_ARN']
});

return {
bucket: bucketName,
key: key,
Expand Down
3 changes: 2 additions & 1 deletion test/.env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
MODE=test
MODE=test
TOPIC_ARN=given:arn:from:env
2 changes: 1 addition & 1 deletion test/snsApiMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
},
publish: async (params) => {
expect(params).to.deep.equal(expectedParams);
console.log(`expected head params: ${JSON.stringify(expectedParams)}`);
console.log(`expected publish params: ${JSON.stringify(expectedParams)}`);
return new Promise((resolve, rejected) => resolve());
}
};
21 changes: 0 additions & 21 deletions test/snsEventData.json

This file was deleted.

60 changes: 59 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ const event = JSON.parse(fs.readFileSync('test/s3EventData.json', 'utf8'));

describe('eventhandler', () => {

let s3ApiMock;
let s3ApiMock, snsApiMock;
beforeEach(() => {
s3ApiMock = require('./s3ApiMock');
snsApiMock = require('./snsApiMock');
s3ApiMock.reset();
snsApiMock.reset();
});

it('collect head request without meta data', async () => {
Expand All @@ -22,6 +24,34 @@ describe('eventhandler', () => {
Key: "gcp/not-transcoded/sugr1km8s6/f423fbfb-6381-11e8-a23f-c7cbebde15f2.ogg"
});

snsApiMock.expectedPublishParams(
{
Message: "placeholder",
MessageAttributes: {
"api-key-id": {
DataType: "String",
StringValue: "sugr1km8s6"
},
bucket: {
DataType: "String",
StringValue: "s2t-base-s2tbucket-19xbw73dypb0s"
},
key: {
DataType: "String",
StringValue: "gcp/not-transcoded/sugr1km8s6/f423fbfb-6381-11e8-a23f-c7cbebde15f2.ogg"
},
pid: {
DataType: "String",
StringValue: "f423fbfb-6381-11e8-a23f-c7cbebde15f2"
},
"transcribe-provider": {
DataType: "String",
StringValue: "gcp"
}
},
"TopicArn": "given:arn:from:env"
});

s3ApiMock.givenResponseHeadObject({
AcceptRanges: "bytes",
ContentLength: 3191,
Expand Down Expand Up @@ -51,6 +81,34 @@ describe('eventhandler', () => {
Key: "gcp/not-transcoded/sugr1km8s6/f423fbfb-6381-11e8-a23f-c7cbebde15f2.ogg"
});

snsApiMock.expectedPublishParams(
{
Message: "placeholder",
MessageAttributes: {
"api-key-id": {
DataType: "String",
StringValue: "sugr1km8s6"
},
bucket: {
DataType: "String",
StringValue: "s2t-base-s2tbucket-19xbw73dypb0s"
},
key: {
DataType: "String",
StringValue: "gcp/not-transcoded/sugr1km8s6/f423fbfb-6381-11e8-a23f-c7cbebde15f2.ogg"
},
pid: {
DataType: "String",
StringValue: "f423fbfb-6381-11e8-a23f-c7cbebde15f2"
},
"transcribe-provider": {
DataType: "String",
StringValue: "gcp"
}
},
"TopicArn": "given:arn:from:env"
});

s3ApiMock.givenResponseHeadObject({
AcceptRanges: "bytes",
ContentLength: 3191,
Expand Down

0 comments on commit 554be0a

Please sign in to comment.