-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin' into feature/single-account-mul…
…tiple-athletes
- Loading branch information
Showing
6 changed files
with
94 additions
and
40 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useEffect } from "react"; | ||
import { useDispatch } from "react-redux"; | ||
import { useParams } from "react-router-dom"; | ||
|
||
import { removeSecretKey, storeSecretKey } from "@/store/actions/appActions"; | ||
|
||
/** | ||
* Secret key logic abstracted away in a hook for easier readability | ||
*/ | ||
const useSecretKey = (): string => { | ||
// Secret key is provided as a route param to the customer_area page | ||
const { secretKey } = useParams<{ | ||
secretKey: string; | ||
}>(); | ||
const dispatch = useDispatch(); | ||
|
||
// Store secretKey to redux store | ||
// for easier access | ||
useEffect(() => { | ||
dispatch(storeSecretKey(secretKey)); | ||
|
||
return () => { | ||
// remove secretKey from local storage on unmount | ||
dispatch(removeSecretKey); | ||
}; | ||
}, [secretKey]); | ||
|
||
return secretKey; | ||
}; | ||
|
||
export default useSecretKey; |
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
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 |
---|---|---|
|
@@ -5,19 +5,40 @@ import { customers } from "../__testData__/customers.json"; | |
|
||
const saul = customers.saul as Customer; | ||
|
||
describe("Deleted athlete redirect", () => { | ||
beforeEach(() => { | ||
describe("Deleted athlete redirects", () => { | ||
it("Navigates to deleted athlete customer_area and redirects to deleted page", () => { | ||
cy.initAdminApp().then((organization) => | ||
cy.updateCustomers(organization, { | ||
customers: { ...saul, deleted: true }, | ||
} as Record<string, Customer>) | ||
); | ||
}); | ||
|
||
it("Navigates to deleted athlete customer_area and redirects to deleted page", () => { | ||
cy.visit([Routes.CustomerArea, saul.secretKey].join("/")); | ||
cy.url().should("include", "deleted"); | ||
|
||
cy.contains("[email protected]"); | ||
}); | ||
|
||
it("Redirects to appropriate customer area page if the athlete is not deleted", () => { | ||
cy.initAdminApp() | ||
.then((organization) => | ||
cy.updateCustomers(organization, { | ||
customers: { ...saul, deleted: false }, | ||
} as Record<string, Customer>) | ||
) | ||
// We want the unauthenticated context for this one | ||
.then(() => cy.visit([Routes.Deleted, saul.secretKey].join("/"))); | ||
|
||
cy.url().should("include", "customer_area"); | ||
cy.url().should("include", saul.secretKey); | ||
}); | ||
|
||
it("Redirects to the login route if no secret key and user not authenticated", () => { | ||
// We're testing with unauthenticated context -> default route is /login | ||
cy.initAdminApp() | ||
.then(() => cy.signOut()) | ||
.then(() => cy.visit(Routes.Deleted)); | ||
|
||
cy.url().should("include", "login"); | ||
}); | ||
}); |