Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanKiral committed May 10, 2023
1 parent 211a4bb commit 3cd3ae7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 52 deletions.
14 changes: 7 additions & 7 deletions src/cmds/migration/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const runMigrationCommand: yargs.CommandModule = {
client: apiClient,
projectId: projectId,
operation: operation,
saveStatusFromPlugin: plugin?.saveStatus ?? null
saveStatusFromPlugin: plugin?.saveStatus ?? null,
};

const migrationsStatus = await loadMigrationsExecutionStatus(plugin?.readStatus ?? null);
Expand Down Expand Up @@ -213,9 +213,9 @@ export const getRange = (range: string): IRange<number> | null => {

return from <= to
? {
from,
to,
}
from,
to,
}
: null;
};

Expand All @@ -235,9 +235,9 @@ export const getRangeDate = (range: string): IRange<Date> | null => {

return from.getTime() <= to.getTime()
? {
from,
to,
}
from,
to,
}
: null;
};

Expand Down
1 change: 0 additions & 1 deletion src/tests/cmds/run/runMigrationWithRollback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,4 @@ describe('run migration command tests', () => {

expect(mockExit).toHaveBeenCalledWith(0);
});

});
70 changes: 30 additions & 40 deletions src/tests/runMigration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,79 +3,69 @@ import { runMigration } from '../utils/migrationUtils';
import * as statusManager from '../utils/statusManager';
import { createManagementClient } from '@kontent-ai/management-sdk';

jest.spyOn(statusManager, 'markAsCompleted').mockImplementation(async () => { });

jest.spyOn(statusManager, 'markAsCompleted').mockImplementation(async () => {});

describe('statusManager runMigration function', () => {
it('runMigration no rollback function specified should throw', async () => {
const migration: IMigration = {
name: "test_migration",
name: 'test_migration',
module: {
order: 1,
run: async () => { }
}
run: async () => {},
},
};

const returnCode = await runMigration(
{},
migration,
{
client: createManagementClient({ apiKey: '' }),
projectId: 'fcb801c6-fe1d-41cf-af91-ec13802a1ed2',
operation: 'rollback',
saveStatusFromPlugin: null
});
const returnCode = await runMigration({}, migration, {
client: createManagementClient({ apiKey: '' }),
projectId: 'fcb801c6-fe1d-41cf-af91-ec13802a1ed2',
operation: 'rollback',
saveStatusFromPlugin: null,
});

expect(returnCode).toEqual(1);
});

it('runMigration rollback function specified should call rollback', async () => {
const migration: IMigration = {
name: "test_migration",
name: 'test_migration',
module: {
order: 1,
run: async () => { },
rollback: async () => {}
}
run: async () => {},
rollback: async () => {},
},
};

const rollback = jest.spyOn(migration.module, 'rollback');

const returnCode = await runMigration(
{},
migration,
{
client: createManagementClient({ apiKey: '' }),
projectId: 'fcb801c6-fe1d-41cf-af91-ec13802a1ed2',
operation: 'rollback',
saveStatusFromPlugin: null
});
const returnCode = await runMigration({}, migration, {
client: createManagementClient({ apiKey: '' }),
projectId: 'fcb801c6-fe1d-41cf-af91-ec13802a1ed2',
operation: 'rollback',
saveStatusFromPlugin: null,
});

expect(rollback).toBeCalledTimes(1);
expect(returnCode).toEqual(0);
});

it('runMigration should call run', async () => {
const migration: IMigration = {
name: "test_migration",
name: 'test_migration',
module: {
order: 1,
run: async () => { },
rollback: async () => {}
}
run: async () => {},
rollback: async () => {},
},
};

const run = jest.spyOn(migration.module, 'run');

const returnCode = await runMigration(
{},
migration,
{
client: createManagementClient({ apiKey: '' }),
projectId: 'fcb801c6-fe1d-41cf-af91-ec13802a1ed2',
operation: 'run',
saveStatusFromPlugin: null
});
const returnCode = await runMigration({}, migration, {
client: createManagementClient({ apiKey: '' }),
projectId: 'fcb801c6-fe1d-41cf-af91-ec13802a1ed2',
operation: 'run',
saveStatusFromPlugin: null,
});

expect(run).toBeCalledTimes(1);
expect(returnCode).toEqual(0);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/migrationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ interface RunMigrationOptions {
}

export const runMigration = async (migrationsStatus: IStatus, migration: IMigration, options: RunMigrationOptions): Promise<number> => {
const {client, projectId, operation, saveStatusFromPlugin} = options;
const { client, projectId, operation, saveStatusFromPlugin } = options;

console.log(`Running the ${operation === 'rollback' && 'rollback of'} ${migration.name} migration.`);

let isSuccess = true;

try {
if(operation === 'run') {
if (operation === 'run') {
await migration.module.run(client).then(async () => {
await markAsCompleted(migrationsStatus, projectId, migration.name, migration.module.order, operation, saveStatusFromPlugin);
});
Expand Down
2 changes: 0 additions & 2 deletions src/utils/statusManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { fileExists } from './fileUtils';
import * as path from 'path';
import { type StatusPlugin } from './status/statusPlugin';


const migrationStatusFilename = 'status.json';
const pluginsFilename = 'plugins.js';
// let status: IStatus = {};
Expand Down Expand Up @@ -99,7 +98,6 @@ const readFromStatus = (): IStatus => {
console.warn(`Status JSON file is invalid because of ${error instanceof Error ? error.message : 'unknown error.'}. Continuing with empty status.`);
return {};
}

};

const saveStatusToFile = (data: string): void => {
Expand Down

0 comments on commit 3cd3ae7

Please sign in to comment.