Skip to content

Commit

Permalink
fix: make login properly async
Browse files Browse the repository at this point in the history
  • Loading branch information
Jekabs Karklins authored and Jekabs Karklins committed Jan 9, 2023
1 parent aa48ab3 commit 1e58ddf
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions apps/user-office-frontend-e2e/cypress/support/user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
CreateUserMutation,
CreateUserMutationVariables,
ExternalTokenLoginMutation,
FeatureId,
GetFeaturesQuery,
Role,
Expand Down Expand Up @@ -35,17 +36,6 @@ const extTokenStoreStfc = new Map<TestUserId, string>([
['reviewer', 'user'],
]);

const { user1, user2, user3, officer, placeholderUser, reviewer } =
initialDBData.users;
const extTokenStoreOAuth = new Map<TestUserId, string>([
['user1', user1.email],
['user2', user2.email],
['user3', user3.email],
['officer', officer.email],
['placeholderUser', placeholderUser.email],
['reviewer', reviewer.email],
]);

const getAndStoreFeaturesEnabled = (): Cypress.Chainable<GetFeaturesQuery> => {
const api = getE2EApi();
const request = api.getFeatures().then((resp) => {
Expand Down Expand Up @@ -177,12 +167,12 @@ const getExternalToken = async (testUserId: TestUserId) => {
const login = (
idOrCredentials: TestUserId | { email: string; password: string },
role?: number
) => {
): Cypress.Chainable<ExternalTokenLoginMutation> => {
const testUserId = getUserIdFromIdOrCredentials(idOrCredentials);

cy.wrap(getExternalToken(testUserId)).then((externalToken) => {
const request = getExternalToken(testUserId).then(async (externalToken) => {
const api = getE2EApi();
api

return api
.externalTokenLogin({
externalToken: externalToken as string,
redirectUri: 'http://localhost:3000/external-auth', // has to be set because it is a required field
Expand Down Expand Up @@ -212,6 +202,8 @@ const login = (
return resp;
});
});

return cy.wrap(request);
};

const logout = () => {
Expand Down

0 comments on commit 1e58ddf

Please sign in to comment.