From ff41638e2b10df5483819a19fb8c5efcd5ec7a20 Mon Sep 17 00:00:00 2001
From: Jure Ursic <jure@colab.coop>
Date: Wed, 8 Jul 2020 14:03:44 +0200
Subject: [PATCH] update: background user token persistance

---
 cypress/integration/create-channel.spec.js   |  1 +
 cypress/integration/create-job-offer.spec.js |  1 +
 cypress/integration/create-project.spec.js   |  1 +
 cypress/integration/create-user.spec.js      |  1 +
 cypress/integration/edit-channel.spec.js     |  1 +
 cypress/integration/edit-job-offer.spec.js   |  1 +
 cypress/integration/edit-project.spec.js     |  1 +
 cypress/integration/retire-project.spec.js   |  1 +
 cypress/support/commands.js                  | 11 +++++++----
 9 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/cypress/integration/create-channel.spec.js b/cypress/integration/create-channel.spec.js
index 8a89d97d..ba1eaaf4 100644
--- a/cypress/integration/create-channel.spec.js
+++ b/cypress/integration/create-channel.spec.js
@@ -12,6 +12,7 @@ context('Create Channel Browser Testing', () => {
     cy.clearLocalStorage({ domain: null });
     cy.clearCookies({ domain: null });
   });
+  beforeEach(() => cy.setToken());
   it('should visit user login screen', () => cy.userLogin());
   describe('Channel Creation process', () => {
     it('should login', () => cy.login());
diff --git a/cypress/integration/create-job-offer.spec.js b/cypress/integration/create-job-offer.spec.js
index f9681546..1c5b225c 100644
--- a/cypress/integration/create-job-offer.spec.js
+++ b/cypress/integration/create-job-offer.spec.js
@@ -16,6 +16,7 @@ context('Create Job Offer Browser Testing', () => {
     cy.clearLocalStorage({ domain: null });
     cy.clearCookies({ domain: null });
   });
+  beforeEach(() => cy.setToken());
   it('should visit user login screen', () => cy.userLogin());
   describe('Job Offer Creation process', () => {
     it('should login', () => cy.login());
diff --git a/cypress/integration/create-project.spec.js b/cypress/integration/create-project.spec.js
index 65af225f..77652c61 100644
--- a/cypress/integration/create-project.spec.js
+++ b/cypress/integration/create-project.spec.js
@@ -14,6 +14,7 @@ context('Create Project Browser Testing', () => {
     cy.clearLocalStorage({ domain: null });
     cy.clearCookies({ domain: null });
   });
+  beforeEach(() => cy.setToken());
   it('should visit user login screen', () => cy.userLogin());
   describe('Project Creation process', () => {
     it('should login', () => cy.login());
diff --git a/cypress/integration/create-user.spec.js b/cypress/integration/create-user.spec.js
index b6dc3221..f2d94169 100644
--- a/cypress/integration/create-user.spec.js
+++ b/cypress/integration/create-user.spec.js
@@ -16,6 +16,7 @@ context('Create User Browser Testing', () => {
     cy.clearLocalStorage({ domain: null });
     cy.clearCookies({ domain: null });
   });
+  beforeEach(() => cy.setToken());
   it('should visit user login screen', () => cy.userLogin());
   describe('User Creation process', () => {
     it('should login', () => cy.login());
diff --git a/cypress/integration/edit-channel.spec.js b/cypress/integration/edit-channel.spec.js
index 32a702a9..03f3fc5d 100644
--- a/cypress/integration/edit-channel.spec.js
+++ b/cypress/integration/edit-channel.spec.js
@@ -17,6 +17,7 @@ context('Edit Channel Browser Testing', () => {
     cy.clearLocalStorage({ domain: null });
     cy.clearCookies({ domain: null });
   });
+  beforeEach(() => cy.setToken());
   it('should visit user login screen', () => cy.userLogin());
   describe('Channel Edition process', () => {
     it('should login', () => cy.login());
diff --git a/cypress/integration/edit-job-offer.spec.js b/cypress/integration/edit-job-offer.spec.js
index 10a7b270..649a469b 100644
--- a/cypress/integration/edit-job-offer.spec.js
+++ b/cypress/integration/edit-job-offer.spec.js
@@ -20,6 +20,7 @@ context('Edit Job Offer Browser Testing', () => {
     cy.clearLocalStorage({ domain: null });
     cy.clearCookies({ domain: null });
   });
+  beforeEach(() => cy.setToken());
   it('should visit user login screen', () => cy.userLogin());
   describe('Job Offer Edition process', () => {
     it('should login', () => cy.login());
diff --git a/cypress/integration/edit-project.spec.js b/cypress/integration/edit-project.spec.js
index e7a532d7..31482bbf 100644
--- a/cypress/integration/edit-project.spec.js
+++ b/cypress/integration/edit-project.spec.js
@@ -19,6 +19,7 @@ context('Edit Project Browser Testing', () => {
     cy.clearLocalStorage({ domain: null });
     cy.clearCookies({ domain: null });
   });
+  beforeEach(() => cy.setToken());
   it('should visit user login screen', () => cy.userLogin());
   describe('Project Edition process', () => {
     it('should login', () => cy.login());
diff --git a/cypress/integration/retire-project.spec.js b/cypress/integration/retire-project.spec.js
index 36daa5d5..102f0a5d 100644
--- a/cypress/integration/retire-project.spec.js
+++ b/cypress/integration/retire-project.spec.js
@@ -11,6 +11,7 @@ context('Retire Project Browser Testing', () => {
     cy.clearLocalStorage({ domain: null });
     cy.clearCookies({ domain: null });
   });
+  beforeEach(() => cy.setToken());
   it('should visit user login screend', () => cy.userLogin());
   describe('Project Retirement process', () => {
     it('should login', () => cy.login());
diff --git a/cypress/support/commands.js b/cypress/support/commands.js
index 1450915c..6700e645 100644
--- a/cypress/support/commands.js
+++ b/cypress/support/commands.js
@@ -36,19 +36,22 @@ Cypress.Commands.add('login', () => {
     cy.get('.accept-button').click();
     cy.location().should((loc) => {
       expect(loc.pathname).to.eq('/');
+      cy.wrap(Cypress.localStorage.getItem('solid-auth-client')).as('currentUser');
     });
   });
 });
 
+Cypress.Commands.add('setToken', () => {
+  if ( this.currentUser ) {
+    Cypress.localStorage.setItem('solid-auth-client', this.currentUser);
+  }
+});
+
 Cypress.Commands.add('naviagte', route => {
   cy.visit(route);
   cy.location().should((loc) => {
     expect(loc.pathname).to.eq(route);
   });
-  // Workaround - seems to be a bug when accessing the route directly
-  cy.get('.accept-button').click();
-  cy.wait(2000);
-  // End workaround
 });
 
 Cypress.Commands.add('userLogin', () => {
-- 
GitLab