webstudio/server/test/services/stack_service_test.ts

45 lines
1.6 KiB
TypeScript

import { rmSync } from "fs";
import { StackService } from "../../src/core/services/stack_service";
import { delay } from "../../src/core/helpers/delay";
import { assert, dirname__ } from "../test";
import { mockSimplePipeline } from "../model/mock_pipelines";
import { FileSystemRepository } from "../../src/core/repository/file_system_repository";
import { CreateFolderUseCase } from "../../src/core/usecases/create_folder_usecase";
abstract class IStackServiceTest {
abstract test(): Promise<boolean>;
}
class SimpleTestStackServiceTest extends StackService implements IStackServiceTest {
fileSystemRepository: FileSystemRepository;
constructor() {
super(mockSimplePipeline, dirname__ + "/context/");
this.fileSystemRepository = new FileSystemRepository();
}
async test(): Promise<boolean> {
await this.call();
console.log(this.path);
const testResult = this.fileSystemRepository.readDirRecursive(this.path).equals(["1.txt", "test.txt"], true);
await delay(100);
rmSync(this.path + "example/", { recursive: true });
return testResult;
}
}
export class StackServiceTest {
dirName: string;
fileSystemRepository: FileSystemRepository;
constructor(dirName: string) {
this.dirName = dirName;
this.fileSystemRepository = new FileSystemRepository();
}
public async test() {
const tests = [new SimpleTestStackServiceTest()];
await new CreateFolderUseCase().call(this.dirName + "/context/");
for await (const el of tests) {
assert((await el.test()) === true, el.constructor.name);
await delay(3000);
}
}
}