Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TheodoreKrypton committed Jul 9, 2024
1 parent a9c3126 commit 22bd1b8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
12 changes: 3 additions & 9 deletions src/api/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,8 @@ export const createClient = async () => {
};

export class Client {
file: FileApi;
dir: DirectoryApi;

constructor(
private readonly fileApi: FileApi,
private readonly dirApi: DirectoryApi,
) {
this.file = this.fileApi;
this.dir = this.dirApi;
}
public readonly file: FileApi,
public readonly dir: DirectoryApi,
) {}
}
28 changes: 14 additions & 14 deletions test/cmd/cmd.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ describe('commands', () => {
jest.replaceProperty(process, 'argv', ['ls', '/f1']);
await executor.execute(parse());

const fr = client.getRootDirectory().findFiles(['f1'])[0];
const fd = await client.getFileDesc(fr);
const fr = client.dir.root().findFiles(['f1'])[0];
const fd = await client.file.desc(fr);

expect(Logger.stdout).toHaveBeenCalledWith(
expect.stringContaining(fd.latestVersionId),
Expand Down Expand Up @@ -134,7 +134,7 @@ describe('commands', () => {
jest.replaceProperty(process, 'argv', ['cp', fileName, '/f1']);
await executor.execute(parse());

const f1 = client.getRootDirectory().findFiles(['f1'])[0];
const f1 = client.dir.root().findFiles(['f1'])[0];
expect(f1.name).toEqual('f1');

fs.rmSync(fileName);
Expand All @@ -154,30 +154,30 @@ describe('commands', () => {
const client = await createMockClient();
const executor = getExecutor(client);

await client.uploadFile(
{ under: client.getRootDirectory() },
await client.file.upload(
{ under: client.dir.root() },
{ name: 'f1', buffer: Buffer.from('content') },
);

jest.replaceProperty(process, 'argv', ['rm', '/f1']);
await executor.execute(parse());

expect(client.getRootDirectory().findFiles(['f1']).length).toEqual(0);
expect(client.dir.root().findFiles(['f1']).length).toEqual(0);
});

it('should remove a directory', async () => {
const client = await createMockClient();
const executor = getExecutor(client);

await client.createDirectory({
await client.dir.create({
name: 'd1',
under: client.getRootDirectory(),
under: client.dir.root(),
});

jest.replaceProperty(process, 'argv', ['rm', '/d1']);
await executor.execute(parse());

expect(client.getRootDirectory().findDirs(['d1']).length).toEqual(0);
expect(client.dir.root().findDirs(['d1']).length).toEqual(0);
});

it('should throw an error if path does not exist', async () => {
Expand All @@ -192,11 +192,11 @@ describe('commands', () => {
const client = await createMockClient();
const executor = getExecutor(client);

const d1 = await client.createDirectory({
const d1 = await client.dir.create({
name: 'd1',
under: client.getRootDirectory(),
under: client.dir.root(),
});
await client.uploadFile(
await client.file.upload(
{ under: d1 },
{ name: 'f1', buffer: Buffer.from('content') },
);
Expand All @@ -215,7 +215,7 @@ describe('commands', () => {
jest.replaceProperty(process, 'argv', ['rm', '/d1', '-r']);
await executor.execute(parse());

expect(client.getRootDirectory().findDirs(['d1']).length).toEqual(0);
expect(client.dir.root().findDirs(['d1']).length).toEqual(0);
});
});

Expand All @@ -227,7 +227,7 @@ describe('commands', () => {
jest.replaceProperty(process, 'argv', ['touch', '/f1']);
await executor.execute(parse());

const f1 = client.getRootDirectory().findFiles(['f1'])[0];
const f1 = client.dir.root().findFiles(['f1'])[0];
expect(f1.name).toEqual('f1');
});
});
Expand Down
3 changes: 2 additions & 1 deletion test/mock/mock-tg-client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Client } from 'src/api';
import { FakeGramJSApi } from 'src/api/impl/fake/gramjs';
import { Messages } from 'src/api/impl/fake/messages';
import { FakeTelegraf } from 'src/api/impl/fake/telegraf';

export const createMockClient = async () => {
export const createMockClient = async (): Promise<Client> => {
jest.resetModules();

const mockMessages = new Messages();
Expand Down

0 comments on commit 22bd1b8

Please sign in to comment.