Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: remove zio endpoint implementation #567

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/api/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export class Endpoint {
*/
private setAjaxRequest(path: string, method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE", body?: any, headers?: IHeaderOptions): AjaxRequest {

let apiUrl = this.knoraApiConfig.zioEndpointsList.includes(this.path) ? this.knoraApiConfig.zioApiUrl : this.knoraApiConfig.apiUrl;
let apiUrl = this.knoraApiConfig.apiUrl;

let ajaxRequest: AjaxRequest = {
url: apiUrl + this.path + path,
Expand Down
56 changes: 2 additions & 54 deletions src/knora-api-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ describe("Test class KnoraApiConfig", () => {
apiPath?: string;
jsonWebToken?: string;
logErrors?: boolean;
zioPrefix?: "/zio" | ":5555";
zioEndpoints?: string[]
}

it("should verify parameters", () => {
Expand Down Expand Up @@ -42,8 +40,6 @@ describe("Test class KnoraApiConfig", () => {
apiPort: 1234,
apiPath: "/api",
jsonWebToken: "GAGA",
zioPrefix: "/zio",
zioEndpoints: ['/admin/projects'],
},
{
apiProtocol: "http",
Expand All @@ -52,8 +48,6 @@ describe("Test class KnoraApiConfig", () => {
apiPath: "/api",
jsonWebToken: "GAGA",
logErrors: false,
zioPrefix: ":5555",
zioEndpoints: ['/admin/projects'],
},
{
apiProtocol: "http",
Expand All @@ -62,14 +56,12 @@ describe("Test class KnoraApiConfig", () => {
apiPath: "/api",
jsonWebToken: "GAGA",
logErrors: true,
zioPrefix: ":5555",
zioEndpoints: ['/admin/projects'],
}
];

params.forEach(({apiProtocol, apiHost, apiPort, apiPath, jsonWebToken, logErrors, zioPrefix, zioEndpoints}) => {
params.forEach(({apiProtocol, apiHost, apiPort, apiPath, jsonWebToken, logErrors}) => {

const config = new KnoraApiConfig(apiProtocol, apiHost, apiPort, apiPath, jsonWebToken, logErrors , zioPrefix, zioEndpoints);
const config = new KnoraApiConfig(apiProtocol, apiHost, apiPort, apiPath, jsonWebToken, logErrors);

expect(config).toEqual(jasmine.any(KnoraApiConfig));
expect(config.apiProtocol).toEqual(apiProtocol);
Expand All @@ -88,8 +80,6 @@ describe("Test class KnoraApiConfig", () => {
expect(config.apiPath).toEqual(apiPath === undefined ? "" : apiPath);
expect(config.jsonWebToken).toEqual(jsonWebToken === undefined ? "" : jsonWebToken);
expect(config.logErrors).toEqual(logErrors === undefined ? false : logErrors);
expect(config.zioPrefix).toEqual(zioPrefix === undefined ? "/zio" : zioPrefix)
expect(config.zioEndpoints).toEqual(zioEndpoints === undefined ? [] : zioEndpoints)

});

Expand Down Expand Up @@ -151,46 +141,4 @@ describe("Test class KnoraApiConfig", () => {

});

describe("Test property zioApiUrl", () => {

interface IZioApiUrlData {
param: {
apiProtocol: "http" | "https",
apiHost: string,
zioPrefix?: "/zio" | ":5555",
apiPath?: string,
};
result: string;
}

it("should return correct value", () => {

const data: IZioApiUrlData[] = [
{
param: {apiProtocol: "http", apiHost: "domain.com", zioPrefix: "/zio"},
result: "http://domain.com/zio"
},
{
param: {apiProtocol: "http", apiHost: "domain.com", zioPrefix: ":5555"},
result: "http://domain.com:5555"
},
{
param: {apiProtocol: "http", apiHost: "domain.com", zioPrefix: "/zio", apiPath: "/api"},
result: "http://domain.com/zio/api"
},
{
param: {apiProtocol: "http", apiHost: "domain.com", zioPrefix: ":5555", apiPath: "/api"},
result: "http://domain.com:5555/api"
}
];

data.forEach(({param, result}) => {
const config = new KnoraApiConfig(param.apiProtocol, param.apiHost, null, param.apiPath, undefined, false, param.zioPrefix);
expect(config.zioApiUrl).toBe(result);
});

});

});

});
22 changes: 0 additions & 22 deletions src/knora-api-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,20 @@ export class KnoraApiConfig {
);
}

/**
* The full zio http API URL
*/
get zioApiUrl(): string {
return (
(this.apiProtocol + "://" + this.apiHost) +
this.zioPrefix +
this.apiPath
);
}

/**
* List of endpoints using zio http
*/
get zioEndpointsList(): string[] {
return this.zioEndpoints;
}

/**
* @param apiProtocol the protocol of the API (http or https)
* @param apiHost the DSP-API base URL
* @param apiPort the port of DSP-API
* @param apiPath the base path following host and port, if any.
* @param jsonWebToken token to identify the user
* @param logErrors determines whether errors should be logged to the console
* @param zioPrefix prefix for zio routes, ":5555" is used locally whereas "/zio" is used on servers
* @param zioEndpoints list of zio endpoints
*/
constructor(public apiProtocol: "http" | "https",
public apiHost: string,
public apiPort: number | null = null,
public apiPath: string = "",
public jsonWebToken: string = "",
public logErrors: boolean = false,
public zioPrefix: "/zio" | ":5555" = "/zio",
public zioEndpoints: string[] = []
) {

// Remove port in case it's the default one
Expand Down
3 changes: 1 addition & 2 deletions test-framework/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ export class AppComponent implements OnInit {
undefined,
undefined,
true,
':5555',
['/admin/projects']);
);
this.knoraApiConnection = new KnoraApiConnection(config);
// console.log(this.knoraApiConnection);
this.userCache = new UserCache(this.knoraApiConnection);
Expand Down
Loading