1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-11-27 08:31:20 +02:00

Cypress: single user token

This commit is contained in:
Chen-I Lim 2021-02-09 16:34:54 -08:00
parent 656d1c7851
commit 1a006f47a0
3 changed files with 17 additions and 18 deletions

View File

@ -10,6 +10,11 @@ describe('Create and delete board / card', () => {
const boardTitle = `Test Board (${timestamp})`;
const cardTitle = `Test Card (${timestamp})`;
beforeEach(() => {
localStorage.setItem('sessionId', 'TESTTOKEN');
cy.expect(localStorage.getItem('sessionId')).to.eq('TESTTOKEN');
});
it('Can create and delete a board and card', () => {
cy.visit('/');
cy.contains('+ Add Board').click({force: true});

View File

@ -11,7 +11,7 @@
"check": "eslint --ext .tsx,.ts . --quiet --cache",
"fix": "eslint --ext .tsx,.ts . --quiet --fix --cache",
"i18n-extract": "formatjs extract src/**/*.tsx src/**/*.ts --out-file i18n/tmp.json; formatjs compile i18n/tmp.json --out-file i18n/en.json; rm i18n/tmp.json",
"runserver-test": "cd cypress && ../../bin/focalboard-server --single-user",
"runserver-test": "cd cypress && ../../bin/focalboard-server -single-user TESTTOKEN",
"cypress:ci": "start-server-and-test runserver-test http://localhost:8088 cypress:run",
"cypress:run": "cypress run",
"cypress:run:chrome": "cypress run --browser chrome",

View File

@ -11,16 +11,17 @@ import {Utils} from './utils'
//
class OctoClient {
readonly serverUrl: string
token?: string
readonly readToken?: string
get token(): string {
return localStorage.getItem('sessionId') || ''
}
get readToken(): string {
const queryString = new URLSearchParams(window.location.search)
const readToken = queryString.get('r') || ''
return readToken
}
constructor(
serverUrl?: string,
token?: string,
readToken?: string) {
constructor(serverUrl?: string) {
this.serverUrl = serverUrl || window.location.origin
this.token = token
this.readToken = readToken
Utils.log(`OctoClient serverUrl: ${this.serverUrl}`)
}
@ -46,9 +47,8 @@ class OctoClient {
}
const responseJson = (await this.getJson(response)) as {token?: string}
this.token = responseJson.token
if (responseJson.token !== '') {
localStorage.setItem('sessionId', this.token || '')
localStorage.setItem('sessionId', responseJson.token || '')
return true
}
return false
@ -330,12 +330,6 @@ class OctoClient {
}
}
function getReadToken(): string {
const queryString = new URLSearchParams(window.location.search)
const readToken = queryString.get('r') || ''
return readToken
}
const client = new OctoClient(undefined, localStorage.getItem('sessionId') || '', getReadToken())
const client = new OctoClient()
export default client