Skip to content

Commit

Permalink
fix: unit tests updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfaron committed Jun 28, 2024
1 parent 660b2f7 commit 77676cb
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion projects/aas-portal/src/test/assets/test-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function createContainer(url: string, documents: AASDocument[]): AASConta
documents: documents,
url: url,
name: url,
type: 'AASServer'
type: 'AAS_API'
};
}

Expand Down
10 changes: 5 additions & 5 deletions projects/aas-server/src/test/configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('configuration', function () {
expect(urlToEndpoint('http://localhost:1234/?name=Test')).toEqual({
name: 'Test',
url: 'http://localhost:1234/',
type: 'AASServer',
type: 'AAS_API',
version: 'v3',
} as AASEndpoint);
});
Expand All @@ -25,7 +25,7 @@ describe('configuration', function () {
expect(urlToEndpoint(new URL('http://localhost:1234/?name=Test'))).toEqual({
name: 'Test',
url: 'http://localhost:1234/',
type: 'AASServer',
type: 'AAS_API',
version: 'v3',
} as AASEndpoint);
});
Expand All @@ -34,7 +34,7 @@ describe('configuration', function () {
expect(urlToEndpoint('http://localhost:1234/?name=Test&version=v2')).toEqual({
name: 'Test',
url: 'http://localhost:1234/',
type: 'AASServer',
type: 'AAS_API',
version: 'v2',
} as AASEndpoint);
});
Expand All @@ -43,7 +43,7 @@ describe('configuration', function () {
expect(urlToEndpoint('http://localhost:1234/')).toEqual({
name: 'http://localhost:1234/',
url: 'http://localhost:1234/',
type: 'AASServer',
type: 'AAS_API',
version: 'v3',
} as AASEndpoint);
});
Expand All @@ -61,7 +61,7 @@ describe('configuration', function () {
expect(urlToEndpoint(new URL('opc.tcp://172.16.160.178:30001/I4AASServer?version=v1'))).toEqual({
name: 'I4AASServer',
url: 'opc.tcp://172.16.160.178:30001/I4AASServer',
type: 'OpcuaServer',
type: 'OPC_UA',
version: 'v1',
} as AASEndpoint);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('EndpointsController', function () {
const endpoints: AASEndpoint = {
name: 'Test',
url: 'http://localhost:1234',
type: 'AASServer',
type: 'AAS_API',
};

aasProvider.getEndpoints.mockResolvedValue([endpoints]);
Expand Down
20 changes: 18 additions & 2 deletions projects/common/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,24 @@ export function getEndpointType(url: string | URL): AASEndpointType {
return 'FileSystem';
case 'http:':
case 'https:': {
const pathname = url.pathname;
return pathname && pathname !== '/' ? 'WebDAV' : 'AAS_API';
const param = url.searchParams.get('type');
if (!param) {
return 'AAS_API';
}

switch (param.toLowerCase()) {
case 'aas_api':
case 'aas-api':
return 'AAS_API';
case 'webdav':
return 'WebDAV';
case 'opc-ua':
case 'opcua':
case 'opc_ua':
return 'OPC_UA';
}

throw new Error(`Endpoint type "${param}" is not supported.`);
}
case 'opc.tcp:':
return 'OPC_UA';
Expand Down
14 changes: 9 additions & 5 deletions projects/common/src/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,19 +335,23 @@ describe('index', () => {
});

describe('getEndpointType', () => {
it('gets the endpoint type from an URL string', () => {
it('gets = from http://localhost:1234/', () => {
expect(getEndpointType('http://localhost:1234/')).toEqual('AAS_API');
});

it('gets the endpoint type from a URL', () => {
it('gets "AAS_API" from http://localhost:1234/?type=aas-api', () => {
expect(getEndpointType('http://localhost:1234/?type=aas-api')).toEqual('AAS_API');
});

it('gets "OPC_UA" from opc.tcp://localhost:1234/I4AASServer', () => {
expect(getEndpointType(new URL('opc.tcp://localhost:1234/I4AASServer'))).toEqual('OPC_UA');
});

it('gets "AASServer" as default', () => {
expect(getEndpointType('http://localhost:1234/endpoints/sample')).toEqual('WebDAV');
it('gets "WebDAV" from http://localhost:1234/endpoints/sample?type=webdav', () => {
expect(getEndpointType('http://localhost:1234/endpoints/sample?type=webdav')).toEqual('WebDAV');
});

it('gets "WebDAV" as default', () => {
it('gets "FileSystem" from file:///endpoints/samples', () => {
expect(getEndpointType('file:///endpoints/samples')).toEqual('FileSystem');
});
});
Expand Down

0 comments on commit 77676cb

Please sign in to comment.