Skip to content

Commit f4f4dc4

Browse files
committed
feat: implement unit tests without m2m token
1 parent 5abeb1a commit f4f4dc4

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

test/prepare.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ require('../src/bootstrap')
66

77
const prepare = require('mocha-prepare')
88
const nock = require('nock')
9-
const testData = require('./testData')
109

1110
prepare(function (done) {
1211
let directProjectId
@@ -16,9 +15,6 @@ prepare(function (done) {
1615
if (path.includes('/projects')) {
1716
return '/_projects'
1817
}
19-
if (path.includes('/token')) { // match auth0 url
20-
return '/_m2mAuth'
21-
}
2218
return path
2319
})
2420
.get('/_projects')
@@ -32,11 +28,6 @@ prepare(function (done) {
3228
.reply(200, (uri, requestBody) => {
3329
directProjectId = requestBody.directProjectId
3430
})
35-
.post('/_m2mAuth')
36-
.reply(200, {
37-
access_token: testData.token.m2m,
38-
expiry: 8400
39-
})
4031
.get('/health')
4132
.reply(200, { checksRun: 1 })
4233
done()

test/processor.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const { initDB } = require('../scripts/init-db')
1313
const { insertData } = require('../scripts/test-data')
1414
const { getInformixConnection, getKafkaOptions } = require('../src/common/helper')
1515
const projectService = require('../src/services/ProjectService')
16+
const sinon = require('sinon')
17+
const helper = require('../src/common/helper')
1618

1719
describe('Topcoder - Legacy Project Processor E2E Test', () => {
1820
let app
@@ -90,6 +92,8 @@ describe('Topcoder - Legacy Project Processor E2E Test', () => {
9092
}
9193

9294
before(async () => {
95+
sinon.stub(helper, 'getM2MToken').value(() => Promise.resolve('dummy-token'))
96+
9397
// inject logger with log collector
9498
logger.info = (message) => {
9599
infoLogs.push(message)
@@ -140,6 +144,8 @@ describe('Topcoder - Legacy Project Processor E2E Test', () => {
140144
}
141145

142146
await connection.closeAsync()
147+
148+
sinon.reset()
143149
})
144150

145151
beforeEach(() => {

test/testData.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,5 @@ const testTopics = {
241241
}
242242

243243
module.exports = {
244-
testTopics,
245-
token: {
246-
m2m: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik5VSkZORGd4UlRVME5EWTBOVVkzTlRkR05qTXlRamxETmpOQk5UYzVRVUV3UlRFeU56TTJRUSJ9.eyJpc3MiOiJodHRwczovL3RvcGNvZGVyLWRldi5hdXRoMC5jb20vIiwic3ViIjoibWFFMm1hQlN2OWZSVkhqU2xDMzFMRlpTcTZWaGhacUNAY2xpZW50cyIsImF1ZCI6Imh0dHBzOi8vbTJtLnRvcGNvZGVyLWRldi5jb20vIiwiaWF0IjoxNTc1MjMyNTMyLCJleHAiOjE1NzUzMTg5MzIsImF6cCI6Im1hRTJtYUJTdjlmUlZIalNsQzMxTEZaU3E2VmhoWnFDIiwic2NvcGUiOiJyZWFkOmNoYWxsZW5nZXMgd3JpdGU6Y2hhbGxlbmdlcyByZWFkOmdyb3VwcyB1cGRhdGU6c3VibWlzc2lvbiByZWFkOnN1Ym1pc3Npb24gZGVsZXRlOnN1Ym1pc3Npb24gY3JlYXRlOnN1Ym1pc3Npb24gYWxsOnN1Ym1pc3Npb24gdXBkYXRlOnJldmlld190eXBlIHJlYWQ6cmV2aWV3X3R5cGUgZGVsZXRlOnJldmlld190eXBlIGFsbDpyZXZpZXdfdHlwZSB1cGRhdGU6cmV2aWV3X3N1bW1hdGlvbiByZWFkOnJldmlld19zdW1tYXRpb24gZGVsZXRlOnJldmlld19zdW1tYXRpb24gY3JlYXRlOnJldmlld19zdW1tYXRpb24gYWxsOnJldmlld19zdW1tYXRpb24gdXBkYXRlOnJldmlldyByZWFkOnJldmlldyBkZWxldGU6cmV2aWV3IGNyZWF0ZTpyZXZpZXcgYWxsOnJldmlldyByZWFkOmJ1c190b3BpY3Mgd3JpdGU6YnVzX2FwaSByZWFkOnVzZXJfcHJvZmlsZX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