From e45d6fc3d1e3482e4e79cb0a019a03893374798e Mon Sep 17 00:00:00 2001 From: Giulio Davide Date: Wed, 8 Feb 2023 15:02:25 +0100 Subject: [PATCH] added test case for warning of merge --- tests/index.test.js | 62 ++++++++++++++++++++++++++++--------- tests/postDecorator.test.js | 15 +++++---- 2 files changed, 55 insertions(+), 22 deletions(-) diff --git a/tests/index.test.js b/tests/index.test.js index dac86ef..500f4b5 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -49,7 +49,7 @@ tap.test('Plain Custom Service', test => { } test.test('Hello World', async assert => { - const fastify = await setupFastify({ ...baseEnv, MY_REQUIRED_ENV_VAR }) + const fastify = await setupFastify(baseEnv) const response = await fastify.inject({ method: 'GET', @@ -63,7 +63,7 @@ tap.test('Plain Custom Service', test => { }) test.test('Access platform values', async assert => { - const fastify = await setupFastify({ ...baseEnv, MY_REQUIRED_ENV_VAR }) + const fastify = await setupFastify(baseEnv) const response = await fastify.inject({ method: 'GET', url: '/platform-values', @@ -91,7 +91,6 @@ tap.test('Plain Custom Service', test => { test.test('Access platform "miauserproperties" - when USER_PROPERTIES_HEADER_KEY NOT defined - uses default header key', async assert => { const envarWithoutUserProperties = { ...baseEnv, - MY_REQUIRED_ENV_VAR, } delete envarWithoutUserProperties.USER_PROPERTIES_HEADER_KEY @@ -119,7 +118,7 @@ tap.test('Plain Custom Service', test => { }) test.test('Access platform values when not declared', async assert => { - const fastify = await setupFastify({ ...baseEnv, MY_REQUIRED_ENV_VAR }) + const fastify = await setupFastify(baseEnv) const response = await fastify.inject({ method: 'GET', url: '/platform-values', @@ -140,7 +139,7 @@ tap.test('Plain Custom Service', test => { }) test.test('Send form encoded data', async assert => { - const fastify = await setupFastify({ ...baseEnv, MY_REQUIRED_ENV_VAR }) + const fastify = await setupFastify(baseEnv) const response = await fastify.inject({ method: 'POST', @@ -164,7 +163,7 @@ tap.test('Plain Custom Service', test => { test.test('Can return a stream', async assert => { const filename = './tests/services/plain-custom-service.js' const readFile = promisify(fs.readFile) - const fastify = await setupFastify({ ...baseEnv, MY_REQUIRED_ENV_VAR }) + const fastify = await setupFastify(baseEnv) const response = await fastify.inject({ method: 'GET', url: '/stream', @@ -179,7 +178,7 @@ tap.test('Plain Custom Service', test => { test.test('Send some json, with validation', async assert => { const payload = { some: 'stuff' } - const fastify = await setupFastify({ ...baseEnv, MY_REQUIRED_ENV_VAR }) + const fastify = await setupFastify(baseEnv) const response = await fastify.inject({ method: 'POST', url: '/validation', @@ -256,7 +255,7 @@ tap.test('Plain Custom Service', test => { test.test('custom body parsing', async assert => { const customType = 'application/custom-type' const payload = { hello: 'world' } - const fastify = await setupFastify({ ...baseEnv, MY_REQUIRED_ENV_VAR }) + const fastify = await setupFastify(baseEnv) const response = await fastify.inject({ method: 'POST', url: '/', @@ -271,7 +270,7 @@ tap.test('Plain Custom Service', test => { }) test.test('Healtiness handler can see decoration', async assert => { - const fastify = await setupFastify({ ...baseEnv, MY_REQUIRED_ENV_VAR }) + const fastify = await setupFastify(baseEnv) const response = await fastify.inject({ method: 'GET', url: '/-/healthz', @@ -281,7 +280,7 @@ tap.test('Plain Custom Service', test => { }) test.test('returns mia headers - empty', async assert => { - const fastify = await setupFastify({ ...baseEnv, MY_REQUIRED_ENV_VAR }) + const fastify = await setupFastify(baseEnv) const response = await fastify.inject({ method: 'GET', @@ -293,7 +292,7 @@ tap.test('Plain Custom Service', test => { }) test.test('returns mia headers - filled', async assert => { - const fastify = await setupFastify({ ...baseEnv, MY_REQUIRED_ENV_VAR }) + const fastify = await setupFastify(baseEnv) const response = await fastify.inject({ method: 'GET', @@ -385,7 +384,7 @@ tap.test('Advanced config', test => { } test.test('it accepts advanced config', async assert => { - const fastify = await setupFastify({ ...baseEnv, MY_REQUIRED_ENV_VAR }) + const fastify = await setupFastify(baseEnv) const response = await fastify.inject({ method: 'POST', @@ -433,7 +432,7 @@ tap.test('Service with API formats', t => { } t.test('it validates date-time', async t => { - const fastify = await setupFastify({ ...baseEnv, MY_REQUIRED_ENV_VAR }) + const fastify = await setupFastify(baseEnv) const someDate = '2021-10-12T15:46:39.081Z' const response = await fastify.inject({ @@ -456,7 +455,7 @@ tap.test('Service with API formats', t => { }) t.test('fails for invalid date', async t => { - const fastify = await setupFastify({ ...baseEnv, MY_REQUIRED_ENV_VAR }) + const fastify = await setupFastify(baseEnv) const response = await fastify.inject({ method: 'POST', @@ -480,3 +479,38 @@ tap.test('Service with API formats', t => { t.end() }) + +tap.test('baseEnv with first level properties', t => { + async function setupFastify(envVariables) { + const fastify = await lc39('./tests/services/if-then-else-env-validation-custom-service.js', { + logLevel: 'silent', + envVariables, + }) + return fastify + } + + t.test('it should fail the build', async t => { + try { + await setupFastify({ + ...baseEnv, + if: { + properties: { + field: { + const: 'value', + }, + }, + }, + then: { + required: [ + 'field1', + ], + }, + }) + t.fail() + } catch (error) { + t.ok(error) + } + }) + + t.end() +}) diff --git a/tests/postDecorator.test.js b/tests/postDecorator.test.js index 60c6366..0247c57 100644 --- a/tests/postDecorator.test.js +++ b/tests/postDecorator.test.js @@ -25,7 +25,6 @@ const GROUPS_HEADER_KEY = 'groups-header-key' const CLIENTTYPE_HEADER_KEY = 'clienttype-header-key' const BACKOFFICE_HEADER_KEY = 'backoffice-header-key' const MICROSERVICE_GATEWAY_SERVICE_NAME = 'microservice-gateway' -const MY_REQUIRED_ENV_VAR = 'value' const baseEnv = { USERID_HEADER_KEY, USER_PROPERTIES_HEADER_KEY, @@ -45,7 +44,7 @@ async function setupFastify(envVariables) { tap.test('Test Post Decorator function', test => { test.test('Return the signal to not change the response', async assert => { - const fastify = await setupFastify({ ...baseEnv, MY_REQUIRED_ENV_VAR }) + const fastify = await setupFastify(baseEnv) const response = await fastify.inject({ method: 'POST', @@ -71,7 +70,7 @@ tap.test('Test Post Decorator function', test => { }) test.test('Return a modified body response', async assert => { - const fastify = await setupFastify({ ...baseEnv, MY_REQUIRED_ENV_VAR }) + const fastify = await setupFastify(baseEnv) const response = await fastify.inject({ method: 'POST', @@ -102,7 +101,7 @@ tap.test('Test Post Decorator function', test => { }) test.test('Return a modified headers response', async assert => { - const fastify = await setupFastify({ ...baseEnv, MY_REQUIRED_ENV_VAR }) + const fastify = await setupFastify(baseEnv) const response = await fastify.inject({ method: 'POST', @@ -132,7 +131,7 @@ tap.test('Test Post Decorator function', test => { }) test.test('Test a bad handler that doesn\'t return the right type', async assert => { - const fastify = await setupFastify({ ...baseEnv, MY_REQUIRED_ENV_VAR }) + const fastify = await setupFastify(baseEnv) const response = await fastify.inject({ method: 'POST', @@ -162,7 +161,7 @@ tap.test('Test Post Decorator function', test => { }) test.test('abortChain', async assert => { - const fastify = await setupFastify({ ...baseEnv, MY_REQUIRED_ENV_VAR }) + const fastify = await setupFastify(baseEnv) const response = await fastify.inject({ method: 'POST', @@ -194,7 +193,7 @@ tap.test('Test Post Decorator function', test => { }) test.test('is able to access to the mia headers correctly', async assert => { - const fastify = await setupFastify({ ...baseEnv, MY_REQUIRED_ENV_VAR }) + const fastify = await setupFastify(baseEnv) const response = await fastify.inject({ method: 'POST', @@ -226,7 +225,7 @@ tap.test('Test Post Decorator function', test => { }) test.test('addPostDecorator is chainable', async assert => { - const fastify = await setupFastify({ ...baseEnv, MY_REQUIRED_ENV_VAR }) + const fastify = await setupFastify(baseEnv) const response = await fastify.inject({ method: 'POST',