Skip to content

Commit 76768bc

Browse files
authored
Tape tests (#22)
* adding circleCI setup (#1) (#2) * message template changes (#3) * added config to be loaded from environmental variables * added healthcheck * Add Dockerfile and dockerignore * settings error fixed
1 parent bf4aaa9 commit 76768bc

18 files changed

Lines changed: 2071 additions & 190 deletions

‎.circleci/config.yml‎

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -166,66 +166,66 @@ jobs:
166166
paths:
167167
- node_modules
168168

169-
# test-unit:
170-
# <<: *defaults_working_directory
171-
# <<: *defaults_docker_node
172-
# steps:
173-
# - checkout
174-
# - run:
175-
# name: Install general dependencies
176-
# command: *defaults_Dependencies
177-
# - run:
178-
# <<: *defaults_environment
179-
# - restore_cache:
180-
# key: dependency-cache-{{ checksum "CACHE_VERSION.txt" }}-{{ checksum "package.json" }}
181-
# - run:
182-
# name: Install tape, tapes and tap-xunit
183-
# command: npm install -g tape tapes tap-xunit
184-
# - run:
185-
# name: Create dir for test results
186-
# command: mkdir -p ./test/results
187-
# - run:
188-
# name: Execute unit tests
189-
# command: npm -s run test:xunit > ./test/results/tape.xml
190-
# - store_artifacts:
191-
# path: ./test/results
192-
# prefix: test
193-
# - store_test_results:
194-
# path: ./test/results
169+
test-unit:
170+
<<: *defaults_working_directory
171+
<<: *defaults_docker_node
172+
steps:
173+
- checkout
174+
- run:
175+
name: Install general dependencies
176+
command: *defaults_Dependencies
177+
- run:
178+
<<: *defaults_environment
179+
- restore_cache:
180+
key: dependency-cache-{{ checksum "CACHE_VERSION.txt" }}-{{ checksum "package.json" }}
181+
- run:
182+
name: Install tape, tapes and tap-xunit
183+
command: npm install -g tape tapes tap-xunit
184+
- run:
185+
name: Create dir for test results
186+
command: mkdir -p ./test/results
187+
- run:
188+
name: Execute unit tests
189+
command: npm -s run test:xunit > ./test/results/tape.xml
190+
- store_artifacts:
191+
path: ./test/results
192+
prefix: test
193+
- store_test_results:
194+
path: ./test/results
195195

196-
# test-coverage:
197-
# <<: *defaults_working_directory
198-
# <<: *defaults_docker_node
199-
# steps:
200-
# - checkout
201-
# - run:
202-
# name: Install general dependencies
203-
# command: *defaults_Dependencies
204-
# - run:
205-
# <<: *defaults_environment
206-
# - run:
207-
# name: Install AWS CLI dependencies
208-
# command: *defaults_awsCliDependencies
209-
# - restore_cache:
210-
# key: dependency-cache-{{ checksum "CACHE_VERSION.txt" }}-{{ checksum "package.json" }}
211-
# - run:
212-
# name: Execute code coverage check
213-
# command: npm -s run test:coverage-check
214-
# - store_artifacts:
215-
# path: coverage
216-
# prefix: test
217-
# - store_test_results:
218-
# path: coverage
219-
# - run:
220-
# name: Copy code coverage to SonarQube
221-
# command: |
222-
# if [ "${CIRCLE_BRANCH}" == "master" ];
223-
# then
224-
# echo "Sending lcov.info to SonarQube..."
225-
# aws s3 cp coverage/lcov.info $AWS_S3_DIR_SONARQUBE/central-ledger/lcov.info
226-
# else
227-
# echo "Not a release (env CIRCLE_BRANCH != 'master'), skipping sending lcov.info to SonarQube."
228-
# fi
196+
test-coverage:
197+
<<: *defaults_working_directory
198+
<<: *defaults_docker_node
199+
steps:
200+
- checkout
201+
- run:
202+
name: Install general dependencies
203+
command: *defaults_Dependencies
204+
- run:
205+
<<: *defaults_environment
206+
- run:
207+
name: Install AWS CLI dependencies
208+
command: *defaults_awsCliDependencies
209+
- restore_cache:
210+
key: dependency-cache-{{ checksum "CACHE_VERSION.txt" }}-{{ checksum "package.json" }}
211+
- run:
212+
name: Execute code coverage check
213+
command: npm -s run test:coverage-check
214+
- store_artifacts:
215+
path: coverage
216+
prefix: test
217+
- store_test_results:
218+
path: coverage
219+
- run:
220+
name: Copy code coverage to SonarQube
221+
command: |
222+
if [ "${CIRCLE_BRANCH}" == "master" ];
223+
then
224+
echo "Sending lcov.info to SonarQube..."
225+
aws s3 cp coverage/lcov.info $AWS_S3_DIR_SONARQUBE/central-ledger/lcov.info
226+
else
227+
echo "Not a release (env CIRCLE_BRANCH != 'master'), skipping sending lcov.info to SonarQube."
228+
fi
229229
230230
# test-integration:
231231
# machine: true

‎README.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@ Stand-alone email service that consumes messages from kafka topic, produced by t
33
The central-notificattions repo is available [here](https://github.com/mojaloop/central-notifications/tree/master)
44
The email-notifier flow is available [here](https://github.com/mojaloop/central-notifications/tree/master#Notifierflowseparateservice)
55

6+
## Mac OS installation problems
7+
8+
If you have this or similar error during installation:
9+
10+
```
11+
npm install
12+
> node-gyp rebuild
13+
clang: error: linker command failed with exit code 1
14+
```
15+
16+
add the following environmental variables:
17+
```
18+
export CPPFLAGS=-I/usr/local/opt/openssl/include
19+
export LDFLAGS=-L/usr/local/opt/openssl/lib
20+
```
21+
622
## Config
723

824
Whole config is located [here](config/default.json)

‎istanbul.yml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
instrumentation:
2+
include-all-sources: true
3+
excludes: []
4+
check:
5+
global:
6+
statements: 80
7+
lines: 80
8+
branches: 80
9+
functions: 80
10+
each:
11+
statements: 80
12+
lines: 80
13+
branches: 80
14+
functions: 80

‎package.json‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424
},
2525
"scripts": {
2626
"start": "node app.js",
27-
"test": "nyc mocha test/unit/**/*.test.js --timeout=4000",
28-
"test:coverage": "istanbul cover tape -- 'test/unit/**/*.test.js'"
27+
"test": "npm run test:unit | faucet",
28+
"test:unit": "tape 'test/unit/**/*.test.js'",
29+
"test:xunit": "tape 'test/unit/**/*test.js' | tap-xunit",
30+
"test:coverage": "istanbul cover tape -- 'test/unit/**/*.test.js'",
31+
"test:coverage-check": "npm run test:coverage && istanbul check-coverage"
2932
},
3033
"repository": {
3134
"type": "git",

‎src/lib/enum.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ const topicMap = {
128128
'get': {
129129
functionality: transferEventType.NOTIFICATION,
130130
action: transferEventAction.EVENT
131+
},
132+
'event': {
133+
functionality: transferEventType.NOTIFICATION,
134+
action: transferEventAction.EVENT
131135
}
132136
}
133137
}

‎src/lib/kafka/consumer.js‎

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -65,39 +65,44 @@ const isConsumerAutoCommitEnabled = (topicName) => {
6565
*/
6666

6767
const createHandler = async (topicName, config) => {
68-
Logger.info(`CreateHandle::connect - creating Consumer for topics: [${topicName}]`)
69-
let consumer = {}
70-
if (Array.isArray(topicName)) {
71-
consumer = new Consumer(topicName, config)
72-
} else {
73-
consumer = new Consumer([topicName], config)
74-
}
68+
try {
69+
Logger.info(`CreateHandle::connect - creating Consumer for topics: [${topicName}]`)
70+
let consumer = {}
71+
if (Array.isArray(topicName)) {
72+
consumer = new Consumer(topicName, config)
73+
} else {
74+
consumer = new Consumer([topicName], config)
75+
}
7576

76-
let autoCommitEnabled = true
77-
if (config.rdkafkaConf !== undefined && config.rdkafkaConf['enable.auto.commit'] !== undefined) {
78-
autoCommitEnabled = config.rdkafkaConf['enable.auto.commit']
79-
}
77+
let autoCommitEnabled = true
78+
if (config.rdkafkaConf !== undefined && config.rdkafkaConf['enable.auto.commit'] !== undefined) {
79+
autoCommitEnabled = config.rdkafkaConf['enable.auto.commit']
80+
}
8081

81-
await consumer.connect().then(async () => {
82-
Logger.info(`CreateHandle::connect - successful connected to topics: [${topicName}]`)
83-
await consumer.consume()
84-
if (Array.isArray(topicName)) {
85-
for (let topic of topicName) { // NOT OK
86-
listOfConsumers[topic] = {
82+
await consumer.connect().then(async () => {
83+
Logger.info(`CreateHandle::connect - successful connected to topics: [${topicName}]`)
84+
await consumer.consume()
85+
if (Array.isArray(topicName)) {
86+
for (let topic of topicName) { // NOT OK
87+
listOfConsumers[topic] = {
88+
consumer: consumer,
89+
autoCommitEnabled: autoCommitEnabled
90+
}
91+
}
92+
} else {
93+
listOfConsumers[topicName] = {
8794
consumer: consumer,
8895
autoCommitEnabled: autoCommitEnabled
8996
}
9097
}
91-
} else {
92-
listOfConsumers[topicName] = {
93-
consumer: consumer,
94-
autoCommitEnabled: autoCommitEnabled
95-
}
96-
}
97-
}).catch((e) => {
98+
}).catch((e) => {
99+
Logger.error(`CreateHandle::connect - error: ${e}`)
100+
throw e
101+
})
102+
} catch (e) {
98103
Logger.error(`CreateHandle::connect - error: ${e}`)
99104
throw e
100-
})
105+
}
101106
}
102107

103108
/**

‎src/lib/kafka/index.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
* @module src/lib/kafka/index
3434
*/
3535

36-
const Producer = require('./producer')
36+
// const Producer = require('./producer')
3737
const Consumer = require('./consumer')
3838
// const Cron = require('./cron')
3939

4040
module.exports = {
41-
Producer,
41+
// Producer,
4242
Consumer
4343
}

‎src/lib/utility.js‎

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const Enum = require('./enum')
5151
* @enum {object} ENUMS~PRODUCER
5252
* @property {string} PRODUCER - PRODUCER config to be fetched
5353
*/
54-
const PRODUCER = 'PRODUCER'
54+
// const PRODUCER = 'PRODUCER'
5555
/**
5656
* The Consumer config required
5757
*
@@ -115,7 +115,7 @@ const STATE = {
115115
* @property {string} CONSUMER - This ENUM is for the CONSUMER
116116
*/
117117
const ENUMS = {
118-
PRODUCER,
118+
// PRODUCER,
119119
CONSUMER,
120120
NOTIFICATION,
121121
STATE,
@@ -274,24 +274,24 @@ const createState = (status, code, description) => {
274274
}
275275
}
276276

277-
/**
278-
* @function createGeneralTopicConfig
279-
*
280-
* @param {string} functionality - the functionality flow. Example: 'transfer' ie: note the case of text
281-
* @param {string} action - the action that applies to the flow. Example: 'prepare' ie: note the case of text
282-
* @param {number} partition - optional partition to produce to
283-
* @param {*} opaqueKey - optional opaque token, which gets passed along to your delivery reports
284-
*
285-
* @returns {object} - Returns newly created general topicConfig
286-
*/
287-
const createGeneralTopicConf = (functionality, action, partition = 0, opaqueKey = 0) => {
288-
return {
289-
topicName: transformGeneralTopicName(functionality, action),
290-
key: Uuid(),
291-
partition,
292-
opaqueKey
293-
}
294-
}
277+
// /**
278+
// * @function createGeneralTopicConfig
279+
// *
280+
// * @param {string} functionality - the functionality flow. Example: 'transfer' ie: note the case of text
281+
// * @param {string} action - the action that applies to the flow. Example: 'prepare' ie: note the case of text
282+
// * @param {number} partition - optional partition to produce to
283+
// * @param {*} opaqueKey - optional opaque token, which gets passed along to your delivery reports
284+
// *
285+
// * @returns {object} - Returns newly created general topicConfig
286+
// */
287+
// const createGeneralTopicConf = (functionality, action, partition = 0, opaqueKey = 0) => {
288+
// return {
289+
// topicName: transformGeneralTopicName(functionality, action),
290+
// key: Uuid(),
291+
// partition,
292+
// opaqueKey
293+
// }
294+
// }
295295

296296
/**
297297
* @function produceGeneralMessage
@@ -311,22 +311,23 @@ const createGeneralTopicConf = (functionality, action, partition = 0, opaqueKey
311311
*
312312
* @returns {object} - Returns a boolean: true if successful, or throws and error if failed
313313
*/
314-
const produceGeneralMessage = async (functionality, action, message, state) => {
315-
let functionalityMapped = functionality
316-
let actionMapped = action
317-
if (Enum.topicMap[functionality] && Enum.topicMap[functionality][action]) {
318-
functionalityMapped = Enum.topicMap[functionality][action].functionality
319-
actionMapped = Enum.topicMap[functionality][action].action
320-
}
321-
await Kafka.Producer.produceMessage(updateMessageProtocolMetadata(message, functionality, action, state),
322-
createGeneralTopicConf(functionalityMapped, actionMapped),
323-
getKafkaConfig(ENUMS.PRODUCER, functionalityMapped.toUpperCase(), actionMapped.toUpperCase()))
324-
}
314+
// const produceGeneralMessage = async (functionality, action, message, state) => {
315+
// let functionalityMapped = functionality
316+
// let actionMapped = action
317+
// if (Enum.topicMap[functionality] && Enum.topicMap[functionality][action]) {
318+
// functionalityMapped = Enum.topicMap[functionality][action].functionality
319+
// actionMapped = Enum.topicMap[functionality][action].action
320+
// }
321+
// await Kafka.Producer.produceMessage(updateMessageProtocolMetadata(message, functionality, action, state),
322+
// createGeneralTopicConf(functionalityMapped, actionMapped),
323+
// getKafkaConfig(ENUMS.PRODUCER, functionalityMapped.toUpperCase(), actionMapped.toUpperCase()))
324+
// }
325325

326326
exports.transformGeneralTopicName = transformGeneralTopicName
327327
exports.getKafkaConfig = getKafkaConfig
328328
exports.updateMessageProtocolMetadata = updateMessageProtocolMetadata
329329
exports.createPrepareErrorStatus = createPrepareErrorStatus
330330
exports.createState = createState
331-
exports.produceGeneralMessage = produceGeneralMessage
331+
// exports.produceGeneralMessage = produceGeneralMessage
332332
exports.ENUMS = ENUMS
333+
// exports.createGeneralTopicConf = createGeneralTopicConf

0 commit comments

Comments
 (0)