Skip to content

Commit

Permalink
added test case for warning of merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Giulio Davide committed Feb 8, 2023
1 parent 8468230 commit e45d6fc
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 22 deletions.
62 changes: 48 additions & 14 deletions tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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: '/',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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({
Expand All @@ -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',
Expand All @@ -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()
})
15 changes: 7 additions & 8 deletions tests/postDecorator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit e45d6fc

Please sign in to comment.