Skip to content

Commit

Permalink
Merge pull request #998 from chardos/prefix-unit-integration-tests
Browse files Browse the repository at this point in the history
chore(tests): generateHapiPath unit tests, prefix integration test
  • Loading branch information
dherault committed Jun 1, 2020
2 parents 6e0b5d3 + f8d1a9e commit c31c41f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/utils/__tests__/generateHapiPath.test.js
@@ -0,0 +1,45 @@
import generateHapiPath from '../generateHapiPath.js'

const serverless = {
service: {
provider: {
stage: 'dev',
},
},
}

describe('generateHapiPath', () => {
test('should generate url starting with a slash', () => {
const options = {}
const result = generateHapiPath('users', options, serverless)
expect(result[0]).toEqual('/')
})

test('should generate url with the stage prepended', () => {
const options = {}
const result = generateHapiPath('users', options, serverless)
expect(result).toEqual('/dev/users')
})

describe('when a prefix option is set', () => {
test('the url should add the prefix', () => {
const options = { prefix: 'some-prefix' }
const result = generateHapiPath('users', options, serverless)
expect(result).toEqual('/some-prefix/dev/users')
})
})

describe('when the noPrependStageInUrl option is set', () => {
test('the url should omit the stage', () => {
const options = { noPrependStageInUrl: true }
const result = generateHapiPath('users', options, serverless)
expect(result).toEqual('/users')
})
})

test('the stage from options should override stage from serverless config', () => {
const options = { stage: 'prod' }
const result = generateHapiPath('users', options, serverless)
expect(result).toEqual('/prod/users')
})
})
23 changes: 23 additions & 0 deletions tests/integration/uncategorized/uncategorized.test.js
Expand Up @@ -64,3 +64,26 @@ describe('noPrependStageInUrl tests', () => {
expect(json.statusCode).toEqual(404)
})
})

describe('prefix options', () => {
// init
beforeAll(() =>
setup({
servicePath: resolve(__dirname),
args: ['--prefix', 'someprefix'],
}),
)

// cleanup
afterAll(() => teardown())

describe('when the prefix option is used', () => {
test('the prefixed path should return a payload', async () => {
const url = joinUrl(TEST_BASE_URL, '/someprefix/dev/uncategorized-1')
const response = await fetch(url)
const json = await response.json()

expect(json).toEqual({ foo: 'bar' })
})
})
})

0 comments on commit c31c41f

Please sign in to comment.