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

All api calls to request/receive upper snake case for GrantType #75

Merged
merged 1 commit into from
Feb 21, 2024
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
4 changes: 2 additions & 2 deletions server/mappers/baseClientApi/addBaseClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseClient } from '../../interfaces/baseClientApi/baseClient'
import { AddBaseClientRequest } from '../../interfaces/baseClientApi/baseClientRequestBody'
import { daysRemaining } from '../../utils/utils'
import { daysRemaining, snakeUpper } from '../../utils/utils'

export default (baseClient: BaseClient): AddBaseClientRequest => {
return {
Expand All @@ -12,7 +12,7 @@ export default (baseClient: BaseClient): AddBaseClientRequest => {
databaseUserName: baseClient.clientCredentials.databaseUserName,
validDays: baseClient.config.expiryDate ? daysRemaining(baseClient.config.expiryDate) : null,
accessTokenValidityMinutes: baseClient.accessTokenValidity ? baseClient.accessTokenValidity / 60 : null,
grantType: baseClient.grantType,
grantType: snakeUpper(baseClient.grantType),
mfa: baseClient.authorisationCode.mfa,
mfaRememberMe: baseClient.authorisationCode.mfaRememberMe,
jwtFields: baseClient.authorisationCode.jwtFields,
Expand Down
4 changes: 2 additions & 2 deletions server/mappers/baseClientApi/updateBaseClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseClient } from '../../interfaces/baseClientApi/baseClient'
import { UpdateBaseClientRequest } from '../../interfaces/baseClientApi/baseClientRequestBody'
import { daysRemaining } from '../../utils/utils'
import { daysRemaining, snakeUpper } from '../../utils/utils'

export default (baseClient: BaseClient): UpdateBaseClientRequest => {
return {
Expand All @@ -11,7 +11,7 @@ export default (baseClient: BaseClient): UpdateBaseClientRequest => {
databaseUserName: baseClient.clientCredentials.databaseUserName,
validDays: baseClient.config.expiryDate ? daysRemaining(baseClient.config.expiryDate) : null,
accessTokenValidityMinutes: baseClient.accessTokenValidity ? baseClient.accessTokenValidity / 60 : null,
grantType: baseClient.grantType,
grantType: snakeUpper(baseClient.grantType),
mfa: baseClient.authorisationCode.mfa,
mfaRememberMe: baseClient.authorisationCode.mfaRememberMe,
jwtFields: baseClient.authorisationCode.jwtFields,
Expand Down
16 changes: 16 additions & 0 deletions server/utils/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
dateTimeFormat,
dateFormat,
dateTimeFormatFromString,
snakeUpper,
} from './utils'

describe('convert to title case', () => {
Expand Down Expand Up @@ -103,6 +104,21 @@ describe('snake', () => {
})
})

describe('snake_upper', () => {
it.each([
['Null', null, null],
['Empty string', '', ''],
['Spaced', 'one two three', 'ONE_TWO_THREE'],
['Snake', 'one_two_three', 'ONE_TWO_THREE'],
['Kebab', 'one-two-three', 'ONE_TWO_THREE'],
['Capitalised', 'One Two THREE', 'ONE_TWO_THREE'],
['Extra spaces', ' one two three ', 'ONE_TWO_THREE'],
['Mixed', 'one-two Three ', 'ONE_TWO_THREE'],
])('%s snakeUpper', (_: string, a: string, expected: string) => {
expect(snakeUpper(a)).toEqual(expected)
})
})

describe('kebab', () => {
it.each([
['Null', null, null],
Expand Down
8 changes: 8 additions & 0 deletions server/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ export const snake = (str: string): string => {
return value
}

export const snakeUpper = (str: string): string => {
if (!str) return str
let value = str.trim().toLowerCase()
value = value.replace(/ /g, '_')
value = value.replace(/-/g, '_')
return value.toUpperCase()
}

export const kebab = (str: string): string => {
if (!str) return str
return snake(str).replace(/_/g, '-')
Expand Down