Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(tests): generateHapiPath unit tests, prefix integration test #998

Merged
merged 3 commits into from Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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' })
})
})
})