-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from agiledigital-labs/IE-345/organization-url…
…-check IE-345/organization-url-check + add url parser
- Loading branch information
Showing
6 changed files
with
145 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
import { z } from 'zod'; | ||
|
||
export const oktaAPIError = z.object({ | ||
export const oktaAPIErrorSchema = z.object({ | ||
status: z.number(), | ||
}); | ||
|
||
export type OktaAPIError = z.infer<typeof oktaAPIError>; | ||
const urlStart = 'https://'; | ||
const urlEnd = '.okta.com'; | ||
export const urlSchema = z | ||
.string() | ||
.url() | ||
.startsWith(urlStart, `URL must start with [${urlStart}].`) | ||
//.co will cause fetch to time out | ||
.endsWith(urlEnd, `URL must end with [${urlEnd}].`) | ||
.min( | ||
urlStart.length + urlEnd.length + 1, | ||
'Domain name must be at least 1 character long.' | ||
) | ||
.refine( | ||
(url) => !url.endsWith('-admin.okta.com'), | ||
'Organisation URL should not be the admin URL. Please remove "-admin" and try again.' | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* eslint-disable functional/no-return-void */ | ||
/* eslint-disable functional/no-expression-statement */ | ||
|
||
import { Left } from 'fp-ts/lib/Either'; | ||
import { parseUrl } from './okta-service'; | ||
|
||
/* eslint-disable functional/functional-parameters */ | ||
describe('Parsing url', () => { | ||
it.each([ | ||
[ | ||
'', | ||
[ | ||
{ | ||
code: 'invalid_string', | ||
message: 'Invalid url', | ||
path: [], | ||
validation: 'url', | ||
}, | ||
{ | ||
code: 'invalid_string', | ||
message: 'URL must start with [https://].', | ||
path: [], | ||
validation: { startsWith: 'https://' }, | ||
}, | ||
{ | ||
code: 'invalid_string', | ||
message: 'URL must end with [.okta.com].', | ||
path: [], | ||
validation: { endsWith: '.okta.com' }, | ||
}, | ||
{ | ||
code: 'too_small', | ||
exact: false, | ||
inclusive: true, | ||
message: 'Domain name must be at least 1 character long.', | ||
minimum: 18, | ||
path: [], | ||
type: 'string', | ||
}, | ||
], | ||
], | ||
[ | ||
'https://trial-admin.okta.com', | ||
[ | ||
{ | ||
code: 'custom', | ||
message: | ||
'Organisation URL should not be the admin URL. Please remove "-admin" and try again.', | ||
path: [], | ||
}, | ||
], | ||
], | ||
])( | ||
'should return a left when the url is invalid', | ||
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types | ||
async (url, issues) => { | ||
const result = await parseUrl(url)(); | ||
expect(result).toEqualLeft( | ||
new Error(`Client error. Invalid URL [${url}].`) | ||
); | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions | ||
expect((result as Left<Error>).left.cause).toEqual(issues); | ||
} | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters