-
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.
- Loading branch information
Showing
2 changed files
with
381 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,290 @@ | ||
import { | ||
LoginStatus, | ||
REQUEST_STATUS, | ||
} from "../src/providers/authentication/terra/hooks/common/entities"; | ||
import { TerraNIHResponse } from "../src/providers/authentication/terra/hooks/useFetchTerraNIHProfile"; | ||
import { TerraResponse } from "../src/providers/authentication/terra/hooks/useFetchTerraProfile"; | ||
import { TerraTermsOfServiceResponse } from "../src/providers/authentication/terra/hooks/useFetchTerraTermsOfService"; | ||
import { TERRA_PROFILE_STATUS } from "../src/providers/authentication/terra/types"; | ||
import { getProfileStatus } from "../src/providers/authentication/terra/utils"; | ||
|
||
const LOGIN_STATUS_NIH_COMPLETED: LoginStatus<TerraNIHResponse> = { | ||
isSuccess: true, | ||
isSupported: true, | ||
requestStatus: REQUEST_STATUS.COMPLETED, | ||
response: undefined, | ||
}; | ||
|
||
const LOGIN_STATUS_TERRA_COMPLETED: LoginStatus<TerraResponse> = { | ||
isSuccess: true, | ||
isSupported: true, | ||
requestStatus: REQUEST_STATUS.COMPLETED, | ||
response: undefined, | ||
}; | ||
|
||
const LOGIN_STATUS_TOS_COMPLETED: LoginStatus<TerraTermsOfServiceResponse> = { | ||
isSuccess: true, | ||
isSupported: true, | ||
requestStatus: REQUEST_STATUS.COMPLETED, | ||
response: undefined, | ||
}; | ||
|
||
const LOGIN_STATUS_TOS_COMPLETED_UNSUCCESSFUL: LoginStatus<TerraTermsOfServiceResponse> = | ||
{ | ||
isSuccess: false, | ||
isSupported: true, | ||
requestStatus: REQUEST_STATUS.COMPLETED, | ||
response: undefined, | ||
}; | ||
|
||
const LOGIN_STATUS_NIH_NOT_STARTED: LoginStatus<TerraNIHResponse> = { | ||
isSuccess: false, | ||
isSupported: true, | ||
requestStatus: REQUEST_STATUS.NOT_STARTED, | ||
response: undefined, | ||
}; | ||
|
||
const LOGIN_STATUS_TERRA_NOT_STARTED: LoginStatus<TerraResponse> = { | ||
isSuccess: false, | ||
isSupported: true, | ||
requestStatus: REQUEST_STATUS.NOT_STARTED, | ||
response: undefined, | ||
}; | ||
|
||
const LOGIN_STATUS_TOS_NOT_STARTED: LoginStatus<TerraTermsOfServiceResponse> = { | ||
isSuccess: false, | ||
isSupported: true, | ||
requestStatus: REQUEST_STATUS.NOT_STARTED, | ||
response: undefined, | ||
}; | ||
|
||
const LOGIN_STATUS_NIH_PENDING: LoginStatus<TerraNIHResponse> = { | ||
isSuccess: false, | ||
isSupported: true, | ||
requestStatus: REQUEST_STATUS.PENDING, | ||
response: undefined, | ||
}; | ||
|
||
const LOGIN_STATUS_TERRA_PENDING: LoginStatus<TerraResponse> = { | ||
isSuccess: false, | ||
isSupported: true, | ||
requestStatus: REQUEST_STATUS.PENDING, | ||
response: undefined, | ||
}; | ||
|
||
const LOGIN_STATUS_TOS_PENDING: LoginStatus<TerraTermsOfServiceResponse> = { | ||
isSuccess: false, | ||
isSupported: true, | ||
requestStatus: REQUEST_STATUS.PENDING, | ||
response: undefined, | ||
}; | ||
|
||
const LOGIN_STATUS_NIH_UNSUPPORTED: LoginStatus<TerraNIHResponse> = { | ||
isSuccess: false, | ||
isSupported: false, | ||
requestStatus: REQUEST_STATUS.NOT_STARTED, | ||
response: undefined, | ||
}; | ||
|
||
const LOGIN_STATUS_TERRA_UNSUPPORTED: LoginStatus<TerraResponse> = { | ||
isSuccess: false, | ||
isSupported: false, | ||
requestStatus: REQUEST_STATUS.NOT_STARTED, | ||
response: undefined, | ||
}; | ||
|
||
const LOGIN_STATUS_TOS_UNSUPPORTED: LoginStatus<TerraTermsOfServiceResponse> = { | ||
isSuccess: false, | ||
isSupported: false, | ||
requestStatus: REQUEST_STATUS.NOT_STARTED, | ||
response: undefined, | ||
}; | ||
|
||
describe("getProfileStatus", () => { | ||
test("not authenticated, services not started", () => { | ||
expect( | ||
getProfileStatus( | ||
false, | ||
LOGIN_STATUS_NIH_NOT_STARTED, | ||
LOGIN_STATUS_TERRA_NOT_STARTED, | ||
LOGIN_STATUS_TOS_NOT_STARTED | ||
) | ||
).toBe(TERRA_PROFILE_STATUS.PENDING); | ||
}); | ||
|
||
test("not authenticated, services unsupported", () => { | ||
expect( | ||
getProfileStatus( | ||
false, | ||
LOGIN_STATUS_NIH_UNSUPPORTED, | ||
LOGIN_STATUS_TERRA_UNSUPPORTED, | ||
LOGIN_STATUS_TOS_UNSUPPORTED | ||
) | ||
).toBe(TERRA_PROFILE_STATUS.PENDING); | ||
}); | ||
|
||
test("not authenticated, services completed", () => { | ||
expect( | ||
getProfileStatus( | ||
false, | ||
LOGIN_STATUS_NIH_COMPLETED, | ||
LOGIN_STATUS_TERRA_COMPLETED, | ||
LOGIN_STATUS_TOS_COMPLETED | ||
) | ||
).toBe(TERRA_PROFILE_STATUS.PENDING); | ||
}); | ||
|
||
test("authenticated, services not started", () => { | ||
expect( | ||
getProfileStatus( | ||
true, | ||
LOGIN_STATUS_NIH_NOT_STARTED, | ||
LOGIN_STATUS_TERRA_NOT_STARTED, | ||
LOGIN_STATUS_TOS_NOT_STARTED | ||
) | ||
).toBe(TERRA_PROFILE_STATUS.PENDING); | ||
}); | ||
|
||
test("authenticated, services pending", () => { | ||
expect( | ||
getProfileStatus( | ||
true, | ||
LOGIN_STATUS_NIH_PENDING, | ||
LOGIN_STATUS_TERRA_PENDING, | ||
LOGIN_STATUS_TOS_PENDING | ||
) | ||
).toBe(TERRA_PROFILE_STATUS.PENDING); | ||
}); | ||
|
||
test("authenticated, nih pending, other services completed", () => { | ||
expect( | ||
getProfileStatus( | ||
true, | ||
LOGIN_STATUS_NIH_PENDING, | ||
LOGIN_STATUS_TERRA_COMPLETED, | ||
LOGIN_STATUS_TOS_COMPLETED | ||
) | ||
).toBe(TERRA_PROFILE_STATUS.PENDING); | ||
}); | ||
|
||
test("authenticated, terra pending, other services completed", () => { | ||
expect( | ||
getProfileStatus( | ||
true, | ||
LOGIN_STATUS_NIH_COMPLETED, | ||
LOGIN_STATUS_TERRA_PENDING, | ||
LOGIN_STATUS_TOS_COMPLETED | ||
) | ||
).toBe(TERRA_PROFILE_STATUS.PENDING); | ||
}); | ||
|
||
test("authenticated, tos pending, other services completed", () => { | ||
expect( | ||
getProfileStatus( | ||
true, | ||
LOGIN_STATUS_NIH_COMPLETED, | ||
LOGIN_STATUS_TERRA_COMPLETED, | ||
LOGIN_STATUS_TOS_PENDING | ||
) | ||
).toBe(TERRA_PROFILE_STATUS.PENDING); | ||
}); | ||
|
||
test("authenticated, nih completed, terra pending, tos not started", () => { | ||
expect( | ||
getProfileStatus( | ||
true, | ||
LOGIN_STATUS_NIH_COMPLETED, | ||
LOGIN_STATUS_TERRA_PENDING, | ||
LOGIN_STATUS_TOS_NOT_STARTED | ||
) | ||
).toBe(TERRA_PROFILE_STATUS.PENDING); | ||
}); | ||
|
||
test("authenticated, nih not started, terra completed, tos pending", () => { | ||
expect( | ||
getProfileStatus( | ||
true, | ||
LOGIN_STATUS_NIH_NOT_STARTED, | ||
LOGIN_STATUS_TERRA_COMPLETED, | ||
LOGIN_STATUS_TOS_PENDING | ||
) | ||
).toBe(TERRA_PROFILE_STATUS.PENDING); | ||
}); | ||
|
||
test("authenticated, nih pending, terra not started, tos completed", () => { | ||
expect( | ||
getProfileStatus( | ||
true, | ||
LOGIN_STATUS_NIH_PENDING, | ||
LOGIN_STATUS_TERRA_NOT_STARTED, | ||
LOGIN_STATUS_TOS_COMPLETED | ||
) | ||
).toBe(TERRA_PROFILE_STATUS.PENDING); | ||
}); | ||
|
||
test("authenticated, services unsupported", () => { | ||
expect( | ||
getProfileStatus( | ||
true, | ||
LOGIN_STATUS_NIH_UNSUPPORTED, | ||
LOGIN_STATUS_TERRA_UNSUPPORTED, | ||
LOGIN_STATUS_TOS_UNSUPPORTED | ||
) | ||
).toBe(TERRA_PROFILE_STATUS.AUTHENTICATED); | ||
}); | ||
|
||
test("authenticated, services completed, tos unsuccessful", () => { | ||
expect( | ||
getProfileStatus( | ||
true, | ||
LOGIN_STATUS_NIH_COMPLETED, | ||
LOGIN_STATUS_TERRA_COMPLETED, | ||
LOGIN_STATUS_TOS_COMPLETED_UNSUCCESSFUL | ||
) | ||
).toBe(TERRA_PROFILE_STATUS.UNAUTHENTICATED); | ||
}); | ||
|
||
test("authenticated, nih unsupported, terra completed, tos completed unsuccessfully", () => { | ||
expect( | ||
getProfileStatus( | ||
true, | ||
LOGIN_STATUS_NIH_UNSUPPORTED, | ||
LOGIN_STATUS_TERRA_COMPLETED, | ||
LOGIN_STATUS_TOS_COMPLETED_UNSUCCESSFUL | ||
) | ||
).toBe(TERRA_PROFILE_STATUS.UNAUTHENTICATED); | ||
}); | ||
|
||
test("authenticated, nih unsupported, other services completed", () => { | ||
expect( | ||
getProfileStatus( | ||
true, | ||
LOGIN_STATUS_NIH_UNSUPPORTED, | ||
LOGIN_STATUS_TERRA_COMPLETED, | ||
LOGIN_STATUS_TOS_COMPLETED | ||
) | ||
).toBe(TERRA_PROFILE_STATUS.AUTHENTICATED); | ||
}); | ||
|
||
test("authenticated, terra completed, other services unsupported", () => { | ||
expect( | ||
getProfileStatus( | ||
true, | ||
LOGIN_STATUS_NIH_UNSUPPORTED, | ||
LOGIN_STATUS_TERRA_COMPLETED, | ||
LOGIN_STATUS_TOS_UNSUPPORTED | ||
) | ||
).toBe(TERRA_PROFILE_STATUS.UNAUTHENTICATED); | ||
}); | ||
|
||
test("authenticated, services completed", () => { | ||
expect( | ||
getProfileStatus( | ||
true, | ||
LOGIN_STATUS_NIH_COMPLETED, | ||
LOGIN_STATUS_TERRA_COMPLETED, | ||
LOGIN_STATUS_TOS_COMPLETED | ||
) | ||
).toBe(TERRA_PROFILE_STATUS.AUTHENTICATED); | ||
}); | ||
}); |
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,91 @@ | ||
import { renderHook } from "@testing-library/react"; | ||
import { useAuthReducer } from "../src/hooks/authentication/auth/useAuthReducer"; | ||
import { useAuthenticationReducer } from "../src/hooks/authentication/authentication/useAuthenticationReducer"; | ||
import { useSessionAuth } from "../src/hooks/authentication/session/useSessionAuth"; | ||
import { | ||
AUTH_STATUS, | ||
AuthState, | ||
} from "../src/providers/authentication/auth/types"; | ||
import { | ||
AUTHENTICATION_STATUS, | ||
AuthenticationState, | ||
} from "../src/providers/authentication/authentication/types"; | ||
|
||
describe("useSessionAuth", () => { | ||
test("auth status SETTLED with no profile", async () => { | ||
testAuthenticationState( | ||
{ | ||
profile: undefined, | ||
status: AUTHENTICATION_STATUS.SETTLED, | ||
}, | ||
{ | ||
isAuthenticated: false, | ||
status: AUTH_STATUS.SETTLED, | ||
} | ||
); | ||
}); | ||
|
||
test("auth status PENDING with no profile", async () => { | ||
testAuthenticationState( | ||
{ | ||
profile: undefined, | ||
status: AUTHENTICATION_STATUS.PENDING, | ||
}, | ||
{ | ||
isAuthenticated: false, | ||
status: AUTH_STATUS.PENDING, | ||
} | ||
); | ||
}); | ||
|
||
test("auth status PENDING with profile", async () => { | ||
testAuthenticationState( | ||
{ | ||
profile: { | ||
email: "[email protected]", | ||
name: "Test", | ||
}, | ||
status: AUTHENTICATION_STATUS.PENDING, | ||
}, | ||
{ | ||
isAuthenticated: false, | ||
status: AUTH_STATUS.PENDING, | ||
} | ||
); | ||
}); | ||
|
||
test("auth status SETTLED with profile", async () => { | ||
testAuthenticationState( | ||
{ | ||
profile: { | ||
email: "[email protected]", | ||
name: "Test", | ||
}, | ||
status: AUTHENTICATION_STATUS.SETTLED, | ||
}, | ||
{ | ||
isAuthenticated: true, | ||
status: AUTH_STATUS.SETTLED, | ||
} | ||
); | ||
}); | ||
}); | ||
|
||
function testAuthenticationState( | ||
authenticationState: AuthenticationState, | ||
expectedAuthState: AuthState | ||
): void { | ||
const { result: authenticationReducerResult } = renderHook(() => | ||
useAuthenticationReducer(authenticationState) | ||
); | ||
const { result: authReducerResult } = renderHook(() => useAuthReducer()); | ||
|
||
renderHook(() => | ||
useSessionAuth({ | ||
authReducer: authReducerResult.current, | ||
authenticationReducer: authenticationReducerResult.current, | ||
}) | ||
); | ||
|
||
expect(authReducerResult.current.authState).toMatchObject(expectedAuthState); | ||
} |