-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clean cypress tests and add auxiliary functions
- Loading branch information
Showing
2 changed files
with
93 additions
and
47 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 |
---|---|---|
|
@@ -6,6 +6,20 @@ const credentials = { | |
port: Cypress.env('psql_db_port'), | ||
}; | ||
|
||
const INSTITUTION_COLUMNS = "institutions (id, active, confirmation_token, creation_date, email, name, nif, token_generation_date)"; | ||
const USER_COLUMNS = "users (user_type, id, creation_date, name, role, state, institution_id)"; | ||
const AUTH_USERS_COLUMNS = "auth_users (auth_type, id, active, email, username, user_id)"; | ||
|
||
const now = new Date(); | ||
const tomorrow = new Date(now); | ||
tomorrow.setDate(now.getDate() + 1); | ||
const dayAfterTomorrow = new Date(now); | ||
dayAfterTomorrow.setDate(now.getDate() + 2); | ||
const yesterday = new Date(now); | ||
yesterday.setDate(now.getDate() - 1); | ||
const dayBeforeYesterday = new Date(now); | ||
dayBeforeYesterday.setDate(now.getDate() - 2); | ||
|
||
Cypress.Commands.add('deleteAllButArs', () => { | ||
cy.task('queryDatabase', { | ||
query: "DELETE FROM ACTIVITY", | ||
|
@@ -19,4 +33,53 @@ Cypress.Commands.add('deleteAllButArs', () => { | |
query: "DELETE FROM USERS WHERE NOT (name = 'ars')", | ||
credentials: credentials, | ||
}); | ||
cy.task('queryDatabase', { | ||
query: "DELETE FROM INSTITUTIONS", | ||
credentials: credentials, | ||
}); | ||
}); | ||
|
||
Cypress.Commands.add('createDemoEntities', () => { | ||
cy.task('queryDatabase', { | ||
query: "INSERT INTO " + INSTITUTION_COLUMNS + generateInstitutionTuple(1), | ||
credentials: credentials, | ||
}) | ||
cy.task('queryDatabase', { | ||
query: "INSERT INTO " + USER_COLUMNS + generateUserTuple(2, "MEMBER","DEMO-MEMBER", "MEMBER", 1), | ||
credentials: credentials, | ||
}) | ||
cy.task('queryDatabase', { | ||
query: "INSERT INTO " + AUTH_USERS_COLUMNS + generateAuthUserTuple(2, "DEMO", "demo-member", 2), | ||
credentials: credentials, | ||
}) | ||
cy.task('queryDatabase', { | ||
query: "INSERT INTO " + USER_COLUMNS + generateUserTuple(3, "VOLUNTEER","DEMO-VOLUNTEER", "VOLUNTEER", "NULL"), | ||
credentials: credentials, | ||
}) | ||
cy.task('queryDatabase', { | ||
query: "INSERT INTO " + AUTH_USERS_COLUMNS + generateAuthUserTuple(3, "DEMO", "demo-volunteer", 3), | ||
credentials: credentials, | ||
}) | ||
}); | ||
|
||
function generateAuthUserTuple(id, authType, username, userId) { | ||
return "VALUES ('" | ||
+ authType + "', '" | ||
+ id + "', 't', '[email protected]','" | ||
+ username + "', '" | ||
+ userId + "')" | ||
} | ||
|
||
function generateUserTuple(id, userType, name, role, institutionId) { | ||
return "VALUES ('" | ||
+ userType + "', '" | ||
+ id + "', '2022-02-06 17:58:21.419878', '" | ||
+ name + "', '" | ||
+ role + "', 'ACTIVE', " | ||
+ institutionId + ")"; | ||
} | ||
|
||
function generateInstitutionTuple(id) { | ||
return "VALUES ('" | ||
+ id + "', 't', 'abca428c09862e89', '2022-08-06 17:58:21.402146','[email protected]', 'DEMO INSTITUTION', '000000000', '2024-02-06 17:58:21.402134')"; | ||
} |