Skip to content

Commit

Permalink
aas-server tests updated
Browse files Browse the repository at this point in the history
  • Loading branch information
raronpxcsw committed Oct 7, 2023
1 parent f9f895b commit 43201a8
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 20 deletions.
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aas-portal-project",
"version": "3.0.3",
"version": "3.0.4",
"description": "Web-based visualization and control of asset administration shells.",
"type": "module",
"scripts": {
Expand Down Expand Up @@ -35,6 +35,7 @@
"./projects/aas-portal"
],
"devDependencies": {
"@babel/plugin-syntax-import-attributes": "^7.22.5",
"@semantic-release/git": "^10.0.1",
"@semantic-release/gitlab": "^12.0.5"
}
Expand Down
9 changes: 8 additions & 1 deletion projects/aas-server/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export default {
],
coverageDirectory: '<rootDir>/../../reports/aas-server',
coverageReporters: ['html', 'json-summary', 'cobertura'],
collectCoverageFrom: [
"<rootDir>/src/app/**/*.[tj]s",
"!<rootDir>/src/app/app.ts"
],
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1"
Expand All @@ -23,7 +27,10 @@ export default {
{
useESM: true,
babelConfig: {
plugins: ["babel-plugin-transform-import-meta"]
plugins: [
"babel-plugin-transform-import-meta",
"@babel/plugin-syntax-import-attributes"
]
}
}
]
Expand Down
1 change: 0 additions & 1 deletion projects/aas-server/src/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { Variable } from './variable.js';
import { Logger } from './logging/logger.js';
import { parseUrl } from './convert.js';

/* istanbul ignore next */
@singleton()
export class App {
constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class ContainersController extends ControllerBase {
public async updateDocument(
@Path() url: string,
@Path() id: string,
@UploadedFile() content: Express.Multer.File
@UploadedFile() content: Express.Multer.File
): Promise<string[]> {
try {
this.logger.start('updateDocument');
Expand Down
2 changes: 1 addition & 1 deletion projects/aas-server/src/app/template/template-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class TemplateStorage {
for (const entry of await this.fileStorage.readDir(dir)) {
const path = $path.join(dir, entry);
if (await this.fileStorage.isDirectory(path)) {
await this.readDirAsync(path, descriptors)
await this.readDirAsync(path, descriptors);
} else {
const format = $path.extname(path).toLowerCase();
switch (format) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,6 @@ describe('ContainersController', function () {
});

it('updateDocument: /api/v1/containers/:url/documents/:id', async function () {
const content: aas.Environment = {
assetAdministrationShells: [],
submodels: [],
conceptDescriptions: []
};

aasProvider.updateDocumentAsync.mockReturnValue(Promise.resolve([]));
auth.hasUserAsync.mockReturnValue(new Promise<boolean>(resolve => resolve(true)));

Expand All @@ -227,7 +221,7 @@ describe('ContainersController', function () {
const response = await request(app)
.put(`/api/v1/containers/${url}/documents/${id}`)
.set('Authorization', `Bearer ${getToken('John')}`)
.send(content);
.attach('content', resolve('./src/test/assets/aas-example.json'));

expect(response.statusCode).toBe(200);
expect(aasProvider.updateDocumentAsync).toHaveBeenCalled();
Expand Down
17 changes: 12 additions & 5 deletions projects/aas-server/src/test/template/template-storage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { TemplateStorage } from '../../app/template/template-storage.js';
import { createSpyObj } from '../utils.js';
import { Logger } from '../../app/logging/logger.js';
import { FileStorage } from '../../app/file-storage/file-storage.js';
import { aas } from 'common';
import { TemplateDescriptor, aas } from 'common';

describe('TemplateStorage', function () {
let templateStorage: TemplateStorage;
Expand All @@ -20,7 +20,7 @@ describe('TemplateStorage', function () {

beforeEach(function () {
logger = createSpyObj<Logger>(['error']);
fileStorage = createSpyObj<FileStorage>(['exists', 'readDir', 'readFile']);
fileStorage = createSpyObj<FileStorage>(['exists', 'isDirectory', 'readDir', 'readFile'], { root: './' });
templateStorage = new TemplateStorage(logger, fileStorage);
})

Expand All @@ -31,19 +31,26 @@ describe('TemplateStorage', function () {
describe('readAsync', function () {
let submodel: aas.Submodel;

beforeEach(function() {
beforeEach(function () {
submodel = {
id: 'http://aas/submodel',
idShort: 'aSubmodel',
kind: 'Instance',
modelType: 'Submodel'
};
});

it('reads all available templates', async function () {
fileStorage.exists.mockResolvedValue(true);
fileStorage.isDirectory.mockResolvedValue(false);
fileStorage.readDir.mockResolvedValue(['submodel.json']);
fileStorage.readFile.mockResolvedValue(Buffer.from(JSON.stringify({submodel})));
await expect(templateStorage.readAsync()).resolves.toEqual([submodel]);
fileStorage.readFile.mockResolvedValue(Buffer.from(JSON.stringify(submodel)));
await expect(templateStorage.readAsync()).resolves.toEqual([{
name: 'submodel.json',
format: '.json',
endpoint: { type: 'file', address: 'submodel.json' },
template: submodel
}] as TemplateDescriptor[]);
});
});
});

0 comments on commit 43201a8

Please sign in to comment.