Skip to content

Commit

Permalink
Add support of single app arn (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
kostia-official authored Apr 28, 2017
1 parent bf23955 commit f0abe69
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 16 deletions.
4 changes: 0 additions & 4 deletions .babelrc

This file was deleted.

7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"fanoutpub": "1.0.3",
"faye": "1.2.4",
"feathers": "2.0.1",
"feathers-authentication": "0.7.0",
"feathers-errors": "2.1.0",
"feathers-hooks": "1.8.1",
"feathers-lg-multi-service-mongoose": "0.1.1",
Expand All @@ -51,19 +50,15 @@
"forever": "0.15.2",
"http-errors": "1.5.0",
"lodash": "4.16.3",
"mandrill-api": "1.0.45",
"mongoose": "4.6.5",
"mongoose-multi-connect": "0.6.1",
"mongoose-rename-id": "1.0.2",
"node-helpers": "~1.0.8",
"postmark": "1.2.1",
"promdash": "1.1.0",
"raven": "0.12.1",
"serve-favicon": "2.3.0",
"simple-express-logger": "2.0.0",
"smart-config": "0.7.4",
"source-map-support": "0.4.2",
"worque": "0.9.3"
"smart-config": "0.8.0"
},
"devDependencies": {
"babel-eslint": "6.0.2",
Expand Down
15 changes: 11 additions & 4 deletions src/helpers/aws-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ function getPushMessage({ platform, message, payload }) {
}

function getPlatformApplicationArn(app) {
app = _.get(app, 'name') || app || defaultApp;

const appArn = appsArns[app];
if (!appArn) throw new Error('No ARN for the app ' + app);
const appArn = getAppName(app, appsArns);
if (!appArn) throw new Error('No ARN for the app ' + JSON.stringify(app));
return appArn;
}

function getAppName(app, appsArns) {
const singeAppName = _.get(app, 'appName') + _.get(app, 'name');
const singeAppArn = appsArns[singeAppName];
if (singeAppArn) return singeAppArn;

const appName = _.get(app, 'name') || app || defaultApp;
return appsArns[appName];
}

function getLogGroup(platformApplicationArn) {
return platformApplicationArn.replace('arn:aws:sns:', 'sns/').replace(/:/g, '/');
}
Expand Down
2 changes: 0 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require('source-map-support').install();

const app = require('./app');
const debug = require('debug')('app');
const config = require('smart-config');
Expand Down
46 changes: 46 additions & 0 deletions test/get-platform-application-arn.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const assert = require('assert');
const config = require('smart-config');
const { getPlatformApplicationArn } = require('../src/helpers/aws-utils');

describe('get arn', () => {
const app = { appName: 'single', name: 'AppStore' };
const singeAppName = app.appName + app.name;

describe('single app arn', () => {
const arn = Date.now().toString();

before(() => {
config.set(`push.appsArns.${singeAppName}`, arn);
});

it('should return proper arn', () => {
const res = getPlatformApplicationArn(app);
assert.equal(res, arn);
});
});

describe('SaaS Enterprise app arn', () => {
const arn = Date.now().toString();

before(() => {
config.set(`push.appsArns.${singeAppName}`, null);
config.set(`push.appsArns.${app.name}`, arn);
});

it('should return proper arn', () => {
const res = getPlatformApplicationArn(app);
assert.equal(res, arn);
});
});

describe('Default app arn', () => {
const defaultApp = config.get('push.defaultApp');
const arn = config.get(`push.appsArns[${defaultApp}]`);

it('should return proper arn', () => {
const res = getPlatformApplicationArn();
assert.equal(res, arn);
});
});

});

0 comments on commit f0abe69

Please sign in to comment.