From a007200a86fbddb5805aa28ae4db001196222741 Mon Sep 17 00:00:00 2001 From: Maciej Barelkowski Date: Mon, 15 Apr 2024 16:01:05 +0200 Subject: [PATCH] test: adjust tests --- app/test/spec/zeebe-api/zeebe-api-spec.js | 234 ++++++++-------------- 1 file changed, 80 insertions(+), 154 deletions(-) diff --git a/app/test/spec/zeebe-api/zeebe-api-spec.js b/app/test/spec/zeebe-api/zeebe-api-spec.js index 2f5d1aa0d..26321a999 100644 --- a/app/test/spec/zeebe-api/zeebe-api-spec.js +++ b/app/test/spec/zeebe-api/zeebe-api-spec.js @@ -662,10 +662,8 @@ describe('ZeebeAPI', function() { const deployResourceSpy = sinon.spy(); const zeebeAPI = mockCamundaClient({ - ZBClient: function() { - return { - deployResource: deployResourceSpy - }; + ZBClient: { + deployResource: deployResourceSpy }, fs: { readFile() { @@ -698,10 +696,8 @@ describe('ZeebeAPI', function() { const deployResourceSpy = sinon.spy(); const zeebeAPI = mockCamundaClient({ - ZBClient: function() { - return { - deployResource: deployResourceSpy - }; + ZBClient: { + deployResource: deployResourceSpy }, fs: { readFile() { @@ -735,10 +731,8 @@ describe('ZeebeAPI', function() { const deployResourceSpy = sinon.spy(); const zeebeAPI = mockCamundaClient({ - ZBClient: function() { - return { - deployResource: deployResourceSpy - }; + ZBClient: { + deployResource: deployResourceSpy }, fs: { readFile() { @@ -776,10 +770,8 @@ describe('ZeebeAPI', function() { const deployResourceSpy = sinon.spy(); const zeebeAPI = mockCamundaClient({ - ZBClient: function() { - return { - deployResource: deployResourceSpy, - }; + ZBClient: { + deployResource: deployResourceSpy, } }); @@ -806,10 +798,8 @@ describe('ZeebeAPI', function() { const deployResourceSpy = sinon.spy(); const zeebeAPI = mockCamundaClient({ - ZBClient: function() { - return { - deployResource: deployResourceSpy, - }; + ZBClient: { + deployResource: deployResourceSpy, } }); @@ -837,10 +827,8 @@ describe('ZeebeAPI', function() { const deployResourceSpy = sinon.spy(); const zeebeAPI = mockCamundaClient({ - ZBClient: function() { - return { - deployResource: deployResourceSpy, - }; + ZBClient: { + deployResource: deployResourceSpy, } }); @@ -868,10 +856,8 @@ describe('ZeebeAPI', function() { const deployResourceSpy = sinon.spy(); const zeebeAPI = mockCamundaClient({ - ZBClient: function() { - return { - deployResource: deployResourceSpy, - }; + ZBClient: { + deployResource: deployResourceSpy, } }); @@ -898,10 +884,8 @@ describe('ZeebeAPI', function() { const deployResourceSpy = sinon.spy(); const zeebeAPI = mockCamundaClient({ - ZBClient: function() { - return { - deployResource: deployResourceSpy, - }; + ZBClient: { + deployResource: deployResourceSpy, } }); @@ -929,10 +913,8 @@ describe('ZeebeAPI', function() { const deployResourceSpy = sinon.spy(); const zeebeAPI = mockCamundaClient({ - ZBClient: function() { - return { - deployResource: deployResourceSpy, - }; + ZBClient: { + deployResource: deployResourceSpy, } }); @@ -960,10 +942,8 @@ describe('ZeebeAPI', function() { const deployResourceSpy = sinon.spy(); const zeebeAPI = mockCamundaClient({ - ZBClient: function() { - return { - deployResource: deployResourceSpy, - }; + ZBClient: { + deployResource: deployResourceSpy, } }); @@ -990,10 +970,8 @@ describe('ZeebeAPI', function() { const deployResourceSpy = sinon.spy(); const zeebeAPI = mockCamundaClient({ - ZBClient: function() { - return { - deployResource: deployResourceSpy, - }; + ZBClient: { + deployResource: deployResourceSpy, } }); @@ -1020,10 +998,8 @@ describe('ZeebeAPI', function() { const deployResourceSpy = sinon.spy(); const zeebeAPI = mockCamundaClient({ - ZBClient: function() { - return { - deployResource: deployResourceSpy, - }; + ZBClient: { + deployResource: deployResourceSpy, } }); @@ -1050,10 +1026,8 @@ describe('ZeebeAPI', function() { const deployResourceSpy = sinon.spy(); const zeebeAPI = mockCamundaClient({ - ZBClient: function() { - return { - deployResource: deployResourceSpy, - }; + ZBClient: { + deployResource: deployResourceSpy, } }); @@ -1081,10 +1055,8 @@ describe('ZeebeAPI', function() { const deployResourceSpy = sinon.spy(); const zeebeAPI = mockCamundaClient({ - ZBClient: function() { - return { - deployResource: deployResourceSpy, - }; + ZBClient: { + deployResource: deployResourceSpy, } }); @@ -1112,10 +1084,8 @@ describe('ZeebeAPI', function() { const deployResourceSpy = sinon.spy(); const zeebeAPI = mockCamundaClient({ - ZBClient: function() { - return { - deployResource: deployResourceSpy, - }; + ZBClient: { + deployResource: deployResourceSpy, } }); @@ -1143,10 +1113,8 @@ describe('ZeebeAPI', function() { const deployResourceSpy = sinon.spy(); const zeebeAPI = mockCamundaClient({ - ZBClient: function() { - return { - deployResource: deployResourceSpy, - }; + ZBClient: { + deployResource: deployResourceSpy, } }); @@ -1175,16 +1143,14 @@ describe('ZeebeAPI', function() { it('should pass configuration', async () => { // given + const configSpy = sinon.spy(); const deployResourceSpy = sinon.spy(); - const ZBClientMock = sinon.spy(function() { - return { - deployResource: deployResourceSpy - }; - }); - const zeebeAPI = mockCamundaClient({ - ZBClient: ZBClientMock + configSpy, + ZBClient: { + deployResource: deployResourceSpy + } }); // when @@ -1203,17 +1169,17 @@ describe('ZeebeAPI', function() { }); // then - const [ url, config ] = ZBClientMock.getCall(0).args; + const config = configSpy.getCall(0).args[0]; // ZBClient is invoked accordingly - expect(url).to.eql(TEST_URL); + expect(config.ZEEBE_ADDRESS).to.eql(TEST_URL); - expect(config.oAuth).to.include.keys({ - audience: 'audience', - clientId: 'clientId', - clientSecret: 'clientSecret', - scope: 'scope', - url: 'oauthURL' + expect(config).to.include.keys({ + CAMUNDA_ZEEBE_OAUTH_AUDIENCE: 'audience', + CAMUNDA_ZEEBE_CLIENT_ID: 'clientId', + CAMUNDA_ZEEBE_CLIENT_SECRET: 'clientSecret', + CAMUNDA_TOKEN_SCOPE: 'scope', + ZEEBE_ADDRESS: 'oauthURL' }); // deployment is executed appropriately @@ -1231,10 +1197,8 @@ describe('ZeebeAPI', function() { const deployResourceSpy = sinon.spy(); const zeebeAPI = mockCamundaClient({ - ZBClient: function() { - return { - deployResource: deployResourceSpy - }; + ZBClient: { + deployResource: deployResourceSpy } }); @@ -1658,12 +1622,8 @@ describe('ZeebeAPI', function() { let usedConfig; const zeebeAPI = mockCamundaClient({ - ZBClient: function(...args) { - usedConfig = args; - - return { - deployResource: noop - }; + configSpy(config) { + usedConfig = config; } }); @@ -1678,7 +1638,7 @@ describe('ZeebeAPI', function() { await zeebeAPI.deploy(parameters); // then - expect(usedConfig[0]).to.eql('https://camunda.com'); + expect(usedConfig.ZEEBE_ADDRESS).to.eql('https://camunda.com'); }); @@ -1688,7 +1648,7 @@ describe('ZeebeAPI', function() { const createSpy = sinon.spy(); const zeebeAPI = mockCamundaClient({ - ZBClient: createSpy + configSpy: createSpy }); const parameters = { @@ -1711,7 +1671,7 @@ describe('ZeebeAPI', function() { const createSpy = sinon.spy(); const zeebeAPI = mockCamundaClient({ - ZBClient: createSpy + configSpy: createSpy }); const parameters = { @@ -1734,13 +1694,10 @@ describe('ZeebeAPI', function() { it('should create new client instance if config is different', async () => { // given - const createSpy = sinon.stub().returns({ - deployResource: noop, - close: noop - }); + const createSpy = sinon.spy(); const zeebeAPI = mockCamundaClient({ - ZBClient: createSpy + configSpy: createSpy }); const parameters = { @@ -1773,7 +1730,6 @@ describe('ZeebeAPI', function() { const zeebeAPI = mockCamundaClient({ ZBClient: { - deployResource: noop, close: closeSpy } }); @@ -1806,12 +1762,8 @@ describe('ZeebeAPI', function() { let usedConfig; const zeebeAPI = mockCamundaClient({ - ZBClient: function(...args) { - usedConfig = args; - - return { - deployResource: noop - }; + configSpy(config) { + usedConfig = config; } }); @@ -1826,7 +1778,7 @@ describe('ZeebeAPI', function() { await zeebeAPI.deploy(parameters); // then - expect(usedConfig[1]).to.have.property('useTLS', true); + expect(usedConfig).to.have.property('useTLS', true); }); @@ -1836,12 +1788,8 @@ describe('ZeebeAPI', function() { let usedConfig; const zeebeAPI = mockCamundaClient({ - ZBClient: function(...args) { - usedConfig = args; - - return { - deployResource: noop - }; + configSpy(config) { + usedConfig = config; } }); @@ -1856,7 +1804,7 @@ describe('ZeebeAPI', function() { await zeebeAPI.deploy(parameters); // then - expect(usedConfig[1]).to.have.property('useTLS', false); + expect(usedConfig).to.have.property('useTLS', false); }); @@ -1866,12 +1814,8 @@ describe('ZeebeAPI', function() { let usedConfig; const zeebeAPI = mockCamundaClient({ - ZBClient: function(...args) { - usedConfig = args; - - return { - deployResource: noop - }; + configSpy(config) { + usedConfig = config; } }); @@ -1886,7 +1830,7 @@ describe('ZeebeAPI', function() { await zeebeAPI.deploy(parameters); // then - expect(usedConfig[1]).to.have.property('useTLS', false); + expect(usedConfig).to.have.property('useTLS', false); }); @@ -1896,12 +1840,8 @@ describe('ZeebeAPI', function() { let usedConfig; const zeebeAPI = mockCamundaClient({ - ZBClient: function(...args) { - usedConfig = args; - - return { - deployResource: noop - }; + configSpy(config) { + usedConfig = config; } }); @@ -1916,7 +1856,7 @@ describe('ZeebeAPI', function() { await zeebeAPI.deploy(parameters); // then - expect(usedConfig[1]).to.have.property('useTLS', true); + expect(usedConfig).to.have.property('CAMUNDA_SECURE_CONNECTION', true); }); @@ -1926,12 +1866,8 @@ describe('ZeebeAPI', function() { let usedConfig; const zeebeAPI = mockCamundaClient({ - ZBClient: function(...args) { - usedConfig = args; - - return { - deployResource: noop - }; + configSpy(config) { + usedConfig = config; } }); @@ -1946,7 +1882,7 @@ describe('ZeebeAPI', function() { await zeebeAPI.deploy(parameters); // then - expect(usedConfig[1]).not.to.have.property('port'); + expect(usedConfig).not.to.have.property('port'); }); @@ -1956,12 +1892,8 @@ describe('ZeebeAPI', function() { let usedConfig; const zeebeAPI = mockCamundaClient({ - ZBClient: function(...args) { - usedConfig = args; - - return { - deployResource: noop - }; + configSpy(config) { + usedConfig = config; } }); @@ -1976,7 +1908,7 @@ describe('ZeebeAPI', function() { await zeebeAPI.deploy(parameters); // then - expect(usedConfig[1]).to.have.property('port', '80'); + expect(usedConfig).to.have.property('port', '80'); }); @@ -1986,12 +1918,8 @@ describe('ZeebeAPI', function() { let usedConfig; const zeebeAPI = mockCamundaClient({ - ZBClient: function(...args) { - usedConfig = args; - - return { - deployResource: noop - }; + configSpy(config) { + usedConfig = config; } }); @@ -2006,7 +1934,7 @@ describe('ZeebeAPI', function() { await zeebeAPI.deploy(parameters); // then - expect(usedConfig[1]).to.have.property('port', '443'); + expect(usedConfig).to.have.property('port', '443'); }); @@ -2019,13 +1947,7 @@ describe('ZeebeAPI', function() { warn: sinon.spy() }; const zeebeAPI = mockCamundaClient({ - ZBClient: function(...args) { - configSpy(...args); - - return { - deployResource: noop - }; - }, + configSpy, flags: { get() { return '/path/to/cert.pem'; @@ -2274,6 +2196,10 @@ function mockCamundaClient(options = {}) { }; class CamundaClient { + constructor(config) { + options.configSpy && options.configSpy(config); + } + getZeebeGrpcApiClient() { return Object.assign({ topology: noop,