-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changing to one CheApiRequestHandler and to dynamicaly injecting head…
…ers.
- Loading branch information
Showing
12 changed files
with
132 additions
and
118 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,24 +1,30 @@ | ||
|
||
import { injectable, inject } from 'inversify'; | ||
import { Logger } from './Logger'; | ||
import { TYPES } from '../inversify.types'; | ||
import { IRequestHandler } from './IRequestHandler'; | ||
import { TestConstants } from '../TestConstants'; | ||
import { RequestType } from './RequestType'; | ||
import { CLASSES } from '../inversify.types'; | ||
import { CheApiRequestHandler } from './requestHandlers/CheApiRequestHandler'; | ||
|
||
@injectable() | ||
export class PreferencesHandler { | ||
|
||
constructor(@inject(TYPES.RequestHandler) private readonly requestHandler: IRequestHandler) { | ||
constructor(@inject(CLASSES.CheApiRequestHandler) private readonly requestHandler: CheApiRequestHandler) { | ||
} | ||
|
||
public async setTerminalType(type: string) { | ||
Logger.debug('PreferencesHandler.setTerminalToDom'); | ||
const response = await this.requestHandler.processRequest(RequestType.GET, `${TestConstants.TS_SELENIUM_BASE_URL}/api/preferences`); | ||
const response = await this.requestHandler.get('api/preferences'); | ||
let userPref = response.data; | ||
let theiaPref = JSON.parse(userPref['theia-user-preferences']); | ||
theiaPref['terminal.integrated.rendererType'] = type; | ||
userPref['theia-user-preferences'] = JSON.stringify(theiaPref); | ||
this.requestHandler.processRequest(RequestType.POST, `${TestConstants.TS_SELENIUM_BASE_URL}/api/preferences`, userPref); | ||
try { | ||
let theiaPref = JSON.parse(userPref['theia-user-preferences']); | ||
theiaPref['terminal.integrated.rendererType'] = type; | ||
userPref['theia-user-preferences'] = JSON.stringify(theiaPref); | ||
this.requestHandler.post('api/preferences', userPref); | ||
} catch (e) { | ||
//setting terminal before running a workspace, so no theia preferences are set | ||
let theiaPref = `{ "terminal.integrated.rendererType":"${type}" }`; | ||
userPref['theia-user-preferences'] = JSON.stringify(JSON.parse(theiaPref)); | ||
this.requestHandler.post('api/preferences', userPref); | ||
} | ||
|
||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
**********************************************************************/ | ||
|
||
import axios, { AxiosResponse } from 'axios'; | ||
import { TestConstants } from '../../TestConstants'; | ||
import { TYPES } from '../../inversify.types'; | ||
import { inject, injectable } from 'inversify'; | ||
import { IHeaderHandler } from './IHeaderHandler'; | ||
|
||
@injectable() | ||
export class CheApiRequestHandler { | ||
|
||
constructor(@inject(TYPES.HeaderHandler) private readonly headerHandler: IHeaderHandler) { | ||
} | ||
|
||
async get(url: string) : Promise<AxiosResponse> { | ||
return await axios.get(this.assembleUrl(url), await this.headerHandler.getHeaders()); | ||
} | ||
|
||
async post(url: string, data?: string) : Promise<AxiosResponse> { | ||
if ( data === undefined ) { | ||
return await axios.post(this.assembleUrl(url), await this.headerHandler.getHeaders()); | ||
} else { | ||
return await axios.post(this.assembleUrl(url), data, await this.headerHandler.getHeaders()); | ||
} | ||
} | ||
|
||
async delete(url: string) : Promise<AxiosResponse> { | ||
return await axios.delete(this.assembleUrl(url), await this.headerHandler.getHeaders()); | ||
} | ||
|
||
private assembleUrl(url: string) : string { | ||
return `${TestConstants.TS_SELENIUM_BASE_URL}/${url}`; | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
**********************************************************************/ | ||
import axios, { AxiosRequestConfig } from 'axios'; | ||
import querystring from 'querystring'; | ||
|
||
import { TestConstants, CLASSES } from '../..'; | ||
import { IHeaderHandler } from './IHeaderHandler'; | ||
import { injectable, inject } from 'inversify'; | ||
import { TokenHandler } from '../TokenHandler'; | ||
|
||
@injectable() | ||
export class MultiUserHeaderHandler implements IHeaderHandler { | ||
|
||
constructor(@inject(CLASSES.TokenHandler) private readonly tokenHandler: TokenHandler) { | ||
} | ||
async getHeaders() : Promise<AxiosRequestConfig> { | ||
let token = await this.tokenHandler.getCheBearerToken(); | ||
return { headers: {'Authorization' : `Bearer ${token}`}}; | ||
} | ||
} | ||
|
||
|
22 changes: 22 additions & 0 deletions
22
tests/e2e/utils/requestHandlers/SingleUserHeaderHandler.ts
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
**********************************************************************/ | ||
|
||
import { IHeaderHandler } from './IHeaderHandler'; | ||
import { injectable } from 'inversify'; | ||
|
||
@injectable() | ||
export class SingleUserHeaderHandler implements IHeaderHandler { | ||
async getHeaders() { | ||
// no headers needs to be set to single user | ||
return {}; | ||
} | ||
} | ||
|
||
|