Skip to content

Commit

Permalink
Merge pull request #16 from fagbokforlaget/DCS-989-adjust-erudio-clie…
Browse files Browse the repository at this point in the history
…nt-to-match-migration-changes
  • Loading branch information
nataszczypiora authored Dec 11, 2024
2 parents 040a08d + 7b2dbe5 commit 5c10ec0
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/content-fusion/content-fusion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class ContentFusion {
private baseUrl: string;

constructor(host: string) {
this.baseUrl = `http://edtech-content-fusion-service.${host}`;
this.baseUrl = `http://edtech-content-fusion-service${host}`;
}

public async getStructureNode(
Expand Down
10 changes: 9 additions & 1 deletion src/erudio-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ export class ErudioClient {
private host: string;

constructor(host: string) {
this.host = host;
if (host) {
if (host[0] === '.') {
this.host = host;
} else {
this.host = `.${host}`;
}
} else {
this.host = '';
}
}

public getStructures = async (
Expand Down
2 changes: 1 addition & 1 deletion src/learning-path/learnig-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class LearningPath {
private readonly baseUrl: string;

constructor(host: string) {
this.baseUrl = `http://edtech-learning-path-runner-service.${host}`;
this.baseUrl = `http://edtech-learning-path-runner-service${host}`;
}

public async getLearningPath(
Expand Down
2 changes: 1 addition & 1 deletion src/localization/localization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class Localization {
private readonly baseUrl: string;

constructor(host: string) {
this.baseUrl = `http://edtech-localization-service.${host}`;
this.baseUrl = `http://edtech-localization-service${host}`;
}

public async getStructureLocalization(
Expand Down
2 changes: 1 addition & 1 deletion src/structure-link/structure-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class StructureLink {
private url: string;

constructor(host: string) {
this.url = `http://edtech-structure-link-service.${host}/structures/links`;
this.url = `http://edtech-structure-link-service${host}/structures/links`;
}

public async listStructureLinks(
Expand Down
4 changes: 2 additions & 2 deletions src/structure/structure.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { PaginatedNodes, Options, Node } from './dto/paginated-nodes-dto';
import { HttpClientProxy } from '../utils/http-client-proxy';
import { Node, Options, PaginatedNodes } from './dto/paginated-nodes-dto';

export class Structure {
private baseUrl: string;

constructor(host: string) {
this.baseUrl = `http://edtech-structure-service.${host}`;
this.baseUrl = `http://edtech-structure-service${host}`;
}

public async getSingleNode(
Expand Down
2 changes: 1 addition & 1 deletion src/tag/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class TagService {
private baseUrl: string;

constructor(host: string) {
this.baseUrl = `http://edtech-tag-store-service.${host}`;
this.baseUrl = `http://edtech-tag-store-service${host}`;
// this.baseUrl = 'http://localhost:3000';
}

Expand Down
61 changes: 61 additions & 0 deletions test/erudio-client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import { randomUUID } from 'crypto';
import { ErudioClient } from '../src/erudio-client';
import { HttpClientProxy } from '../src/utils/http-client-proxy';
import { ServiceType } from '../src/utils/service.types';
import { structureLink } from './data/get-structure-link-data';
import { structureLocalization } from './data/get-structure-localization';
Expand Down Expand Up @@ -262,4 +264,63 @@ describe('Erudio Client', () => {
});
});
});

describe('Should properly set suffix for host value in constructor', () => {
it('Should properly set value for undefined given', async () => {
const namespaceId = randomUUID();
const spy = jest
.spyOn(HttpClientProxy.prototype, 'get')
.mockImplementation(jest.fn());

const client = new ErudioClient(undefined);

client.getStructures(namespaceId);
expect(spy).toBeCalledWith(
`http://edtech-structure-service/structures/${namespaceId}/nodes`,
{ params: undefined },
);
});
it('Should properly set value for empty string given', () => {
const namespaceId = randomUUID();
const spy = jest
.spyOn(HttpClientProxy.prototype, 'get')
.mockImplementation(jest.fn());

const client = new ErudioClient('');

client.getStructures(namespaceId);
expect(spy).toBeCalledWith(
`http://edtech-structure-service/structures/${namespaceId}/nodes`,
{ params: undefined },
);
});
it('Should properly set value for value with dot given', () => {
const namespaceId = randomUUID();
const spy = jest
.spyOn(HttpClientProxy.prototype, 'get')
.mockImplementation(jest.fn());

const client = new ErudioClient('.something');

client.getStructures(namespaceId);
expect(spy).toBeCalledWith(
`http://edtech-structure-service.something/structures/${namespaceId}/nodes`,
{ params: undefined },
);
});
it('Should properly set value for value without dot given', () => {
const namespaceId = randomUUID();
const spy = jest
.spyOn(HttpClientProxy.prototype, 'get')
.mockImplementation(jest.fn());

const client = new ErudioClient('something');

client.getStructures(namespaceId);
expect(spy).toBeCalledWith(
`http://edtech-structure-service.something/structures/${namespaceId}/nodes`,
{ params: undefined },
);
});
});
});

0 comments on commit 5c10ec0

Please sign in to comment.