Commit 8295b94e7442b1c6ae98bfb9331504d62125b005
1 parent
f8555c625f
Exists in
master
CORE prefixes
Showing 4 changed files with 52 additions and 5 deletions Side-by-side Diff
index.js
... | ... | @@ -10,5 +10,6 @@ const config = require('komodo-sdk/config'); |
10 | 10 | global.KOMODO_LOG_LABEL = `KOMODO-CENTER@${(config && typeof config.name === 'string') ? config.name.toUpperCase() : 'SMS'}`; |
11 | 11 | process.title = global.KOMODO_LOG_LABEL; |
12 | 12 | |
13 | +require('./lib/prefixes'); | |
13 | 14 | require('./lib/transport'); |
14 | -require('./lib/apiserver'); | |
15 | 15 | \ No newline at end of file |
16 | +require('./lib/apiserver'); |
lib/prefixes/index.js
... | ... | @@ -0,0 +1,23 @@ |
1 | +'use strict'; | |
2 | + | |
3 | +const coreapi = require('komodo-sdk/coreapi'); | |
4 | + | |
5 | +async function lookup(number) { | |
6 | + if (!number) return; | |
7 | + | |
8 | + const [err, lookupResult] = await coreapi({ | |
9 | + path: '/prefixes/lookup', | |
10 | + method: 'GET', | |
11 | + qs: { | |
12 | + number, | |
13 | + } | |
14 | + }); | |
15 | + | |
16 | + if (err || !lookupResult || lookupResult.error) { | |
17 | + return; | |
18 | + } | |
19 | + | |
20 | + return lookupResult.prefix; | |
21 | +} | |
22 | + | |
23 | +exports.lookup = lookup; |
package-lock.json
... | ... | @@ -2043,9 +2043,9 @@ |
2043 | 2043 | "dev": true |
2044 | 2044 | }, |
2045 | 2045 | "graceful-fs": { |
2046 | - "version": "4.2.1", | |
2047 | - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.1.tgz", | |
2048 | - "integrity": "sha512-b9usnbDGnD928gJB3LrCmxoibr3VE4U2SMo5PBuBnokWyDADTqDPXg4YpwKF1trpH+UbGp7QLicO3+aWEy0+mw==", | |
2046 | + "version": "4.2.2", | |
2047 | + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.2.tgz", | |
2048 | + "integrity": "sha512-IItsdsea19BoLC7ELy13q1iJFNmd7ofZH5+X/pJr90/nRoPEX0DJo1dHDbgtYWOhJhcCgMDTOw84RZ72q6lB+Q==", | |
2049 | 2049 | "optional": true |
2050 | 2050 | }, |
2051 | 2051 | "growl": { |
... | ... | @@ -2557,7 +2557,7 @@ |
2557 | 2557 | } |
2558 | 2558 | }, |
2559 | 2559 | "komodo-sdk": { |
2560 | - "version": "git+http://gitlab.kodesumber.com/komodo/komodo-sdk.git#b9d4c0ca232d01b41a438b21a0b81e2448bd21bd", | |
2560 | + "version": "git+http://gitlab.kodesumber.com/komodo/komodo-sdk.git#277d0d5904a82a2d9d5f0d2dfde4816e7d416ae8", | |
2561 | 2561 | "from": "git+http://gitlab.kodesumber.com/komodo/komodo-sdk.git", |
2562 | 2562 | "requires": { |
2563 | 2563 | "array-unique": "^0.3.2", |
test/prefixes.js
... | ... | @@ -0,0 +1,23 @@ |
1 | +'use strict'; | |
2 | + | |
3 | +/* global describe it */ | |
4 | + | |
5 | +global.KOMODO_SDK_NO_LOG_ON_COREAPI = true; | |
6 | + | |
7 | +const should = require('should'); | |
8 | +const prefixes = require('../lib/prefixes'); | |
9 | + | |
10 | +describe('#prefixes', () => { | |
11 | + describe('#lookup', () => { | |
12 | + it('should return correct prefix', async () => { | |
13 | + const lookupResult = await prefixes.lookup('08180000000'); | |
14 | + lookupResult.should.equal('XL'); | |
15 | + }); | |
16 | + | |
17 | + it('should handle unknown prefix', async () => { | |
18 | + should.not.exist(await prefixes.lookup()); | |
19 | + should.not.exist(await prefixes.lookup('')); | |
20 | + should.not.exist(await prefixes.lookup('9')); | |
21 | + }); | |
22 | + }); | |
23 | +}); | |
0 | 24 | \ No newline at end of file |