From 48a63cbb2c3c12a83d3e8737b41525c33b45ddb2 Mon Sep 17 00:00:00 2001 From: Daniel Vu Date: Mon, 3 Oct 2022 13:13:38 -0500 Subject: [PATCH] Add database reset to Cypress test --- cypress/downloads/downloads.html | Bin 0 -> 4952 bytes cypress/e2e/workspace.cy.js | 1 + cypress/support/commands.ts | 22 ++----------------- package-lock.json | 21 ++++++++++++++++++ package.json | 1 + scripts/seed-database.js | 36 +++++++++++++++++++++++++++++-- 6 files changed, 59 insertions(+), 22 deletions(-) create mode 100644 cypress/downloads/downloads.html diff --git a/cypress/downloads/downloads.html b/cypress/downloads/downloads.html new file mode 100644 index 0000000000000000000000000000000000000000..edeeaf75d2f32b55f973c549774fcd557ad9cd2b GIT binary patch literal 4952 zcmZ{ncTf{dx5nvBniQo<6#)?uNa&$Sk&d7UNC#=5h#);w!9o*|Dn+HYkkI4>6Ob+? zw9uP`CLIHzgd|t*H*@cIznOb>cK4Y*=REt*&d&U_17zhX$;ilbsL06JYUmissAOU( zgk_j$=p_^M6Hb}P$;qk7C}SyD$o`x&P{dM@lYLd@kv*|$myoDf8Gk@Cv;%N>B>q6b zH*7NYU{}_5FGYnTPe1;8UztTp_iV-8A;OWb^G)lJ9AKrLCvNnld@`tL1#5O+_tKNn z$iQ$*UEqSq0Y2*(I~REP<&-?4Ecs`l7fXeJHq*G55be!d0?jW5sJVx2+k`O;@AN|P z3|KX=gmi{l8u)2u167**R`Cavxsa&an%eflnf9A|Z8u$Wa9Sk(#Vo@!+Y+$U@kiKu zOpF3)o&K1WCNwIULsY>amQzp6(z0mQ>hzA9m-`Fbvynrw293L;4PK&e5*gQTk6)b% z^^O4BCm$L5NIbQsQ$@Pb!ija89-*za8_zQ$<&hPc0N0#%{C z+n4^>+W2lvQI)#b69khoM5;?-9jnb><@*DQ`=al05%)HWq&mrFGEFTb9iKdO9_;4? zWd04iQh7@(^j+s(`DCDeZzf(+L4$|jbP@Oo+cJ8#rAu*UZT@Hrf3aW8h*eE);y)Q7 z_y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?B6Eh_&0+`9)QQ)-~mR@{n_xt>>IZ+n<(!3%ok1h2`_>%`d-I?%PP6 zF4ke^+8!@FovS5RbH36w70!9NVB(zedZC(Y!`%){rTm7uU zpA^!rHo@eipzf~#@5cJ<8^bjrke^&2g#nZ?!RdU6#s0(be4X)c zY?)Amy^uPzp7*ERQ06BO84BL { beforeEach(() => { + cy.exec('node scripts/seed-database.js'); // Cypress starts out with a blank slate for each test // so we must tell it to visit our website with the `cy.visit()` command. // Since we want to visit the same URL at the start of all our tests, diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 9823d96..e659acb 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -8,6 +8,7 @@ // commands please read more here: // https://on.cypress.io/custom-commands // *********************************************** +/* eslint-disable @typescript-eslint/no-namespace */ import '@testing-library/cypress/add-commands'; @@ -20,30 +21,11 @@ Cypress.Commands.add('login', () => { }).should('exist'); }); -// -// -// -- This is a parent command -- -// Cypress.Commands.add('login', (email, password) => { ... }) -// -// -// -- This is a child command -- -// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) -// -// -// -- This is a dual command -- -// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) -// -// -// -- This will overwrite an existing command -- -// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) -// - -/* eslint-disable @typescript-eslint/no-namespace */ - declare global { namespace Cypress { interface Chainable { login(): Chainable; + databaseReset(): Chainable; } } } diff --git a/package-lock.json b/package-lock.json index 1e92225..4d82d10 100644 --- a/package-lock.json +++ b/package-lock.json @@ -68,6 +68,7 @@ "@types/md5": "^2.3.2", "@types/node": "17.0.14", "@types/react": "17.0.38", + "@types/shelljs": "^0.8.11", "@typescript-eslint/eslint-plugin": "^5.36.1", "@typescript-eslint/parser": "^5.36.1", "@zeit/next-css": "^1.0.1", @@ -12502,6 +12503,16 @@ "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz", "integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==" }, + "node_modules/@types/shelljs": { + "version": "0.8.11", + "resolved": "https://registry.npmjs.org/@types/shelljs/-/shelljs-0.8.11.tgz", + "integrity": "sha512-x9yaMvEh5BEaZKeVQC4vp3l+QoFj3BXcd4aYfuKSzIIyihjdVARAadYy3SMNIz0WCCdS2vB9JL/U6GQk5PaxQw==", + "dev": true, + "dependencies": { + "@types/glob": "*", + "@types/node": "*" + } + }, "node_modules/@types/sinonjs__fake-timers": { "version": "8.1.1", "resolved": "https://registry.npmjs.org/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.1.tgz", @@ -44146,6 +44157,16 @@ "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz", "integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==" }, + "@types/shelljs": { + "version": "0.8.11", + "resolved": "https://registry.npmjs.org/@types/shelljs/-/shelljs-0.8.11.tgz", + "integrity": "sha512-x9yaMvEh5BEaZKeVQC4vp3l+QoFj3BXcd4aYfuKSzIIyihjdVARAadYy3SMNIz0WCCdS2vB9JL/U6GQk5PaxQw==", + "dev": true, + "requires": { + "@types/glob": "*", + "@types/node": "*" + } + }, "@types/sinonjs__fake-timers": { "version": "8.1.1", "resolved": "https://registry.npmjs.org/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.1.tgz", diff --git a/package.json b/package.json index f62d6d2..7a2d8a6 100644 --- a/package.json +++ b/package.json @@ -89,6 +89,7 @@ "@types/md5": "^2.3.2", "@types/node": "17.0.14", "@types/react": "17.0.38", + "@types/shelljs": "^0.8.11", "@typescript-eslint/eslint-plugin": "^5.36.1", "@typescript-eslint/parser": "^5.36.1", "@zeit/next-css": "^1.0.1", diff --git a/scripts/seed-database.js b/scripts/seed-database.js index 66d4dc2..9794979 100644 --- a/scripts/seed-database.js +++ b/scripts/seed-database.js @@ -60,8 +60,40 @@ function splitStringByNotQuotedSemicolon(input) { } const main = async () => { - shell.exec('npm run db:reset -- --force'); - await seedDatabase(); + // shell.exec('npm run db:reset -- --force'); + const tablesToEmpty = [ + 'ProjectMapPosition', + 'ProjectMapEdgesSet', + 'Issue', + 'KeyIssue', + 'Project', + 'TeamWorkspace', + 'TeamUsers', + 'Team', + 'Workspace', + 'Account', + 'UserPreference', + 'User', + ]; + + for (let table of tablesToEmpty) { + try { + console.log(`Deleting table ${table}`); + await prisma[table].deleteMany({ where: {} }); + } catch (err) { + console.error(`Error deleting table`); + console.error(err); + } + } + try { + console.log('Seeding database'); + await seedDatabase(); + } catch (err) { + console.error('Error seeding database'); + console.error(err); + } + + console.log('Success'); }; main();