1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2025-11-25 22:32:52 +02:00

Adding minimal Test for repository.md #1047

This commit is contained in:
Patrik J. Braun
2025-11-07 23:15:13 +01:00
parent f5b8a0a524
commit d64b969257
2 changed files with 30 additions and 5 deletions

View File

@@ -30,10 +30,8 @@ export class ExtensionRepository {
return text;
}
public async fetchList(): Promise<ExtensionListItem[]> {
const res = await (await fetch(Config.Extensions.repositoryUrl)).text();
const lines = res.split('\n');
public repoMD(text: string): ExtensionListItem[] {
const lines = text.split('\n');
lines.forEach(line => line.trim());
const tableStartLine = lines.findIndex(l => l.startsWith('| **Name** |'));
const tableHeaderLines = 2;
@@ -62,7 +60,12 @@ export class ExtensionRepository {
zipUrl: this.getUrlFromMDLink(entries[3])
});
});
this.extensionsList = extensions;
return extensions;
}
public async fetchList(): Promise<ExtensionListItem[]> {
const res = await (await fetch(Config.Extensions.repositoryUrl)).text();
this.extensionsList = this.repoMD(res);
this.lastUpdate = new Date().getTime();
return this.extensionsList;
}

View File

@@ -0,0 +1,22 @@
import {expect} from 'chai';
import { readFile } from 'fs/promises';
import {ExtensionRepository} from '../../../../../src/backend/model/extension/ExtensionRepository';
import {ProjectPath} from '../../../../../src/backend/ProjectPath';
import path = require('path');
// to help WebStorm to handle the test cases
declare let describe: any;
declare const after: any;
declare const before: any;
declare const it: any;
describe('ExtensionRepository', () => {
it('should parse MD repo file', async () => {
const text = await readFile(path.join(ProjectPath.Root,'extension/REPOSITORY.md'), 'utf8');
const extensions = (new ExtensionRepository()).repoMD(text);
expect(extensions[0].id).to.deep.equal('sample-extension');
});
});