Skip to content

Instantly share code, notes, and snippets.

@brian-lim-42
Created August 27, 2024 15:54
Show Gist options
  • Save brian-lim-42/5357b34827b29010f687167599333820 to your computer and use it in GitHub Desktop.
Save brian-lim-42/5357b34827b29010f687167599333820 to your computer and use it in GitHub Desktop.
import { createMigrationHistory, updateMigrationHistory, setMigrationResult } from './mutation';
import { CustomContext } from '../../../types';
import MigrationService from '../../../core/service/migration/migrationService';
jest.mock('../../../core/service/migration/migrationService');
const mockContext: CustomContext = {
injector: {
get: jest.fn().mockReturnValue(new MigrationService()),
},
securityContext: {},
licensingInfo: {},
};
describe('Migration Mutation Resolvers', () => {
let migrationService: MigrationService;
beforeEach(() => {
migrationService = mockContext.injector.get(MigrationService);
});
describe('createMigrationHistory', () => {
it('should create migration history successfully', async () => {
const mockInput = { migration: { id: '1', name: 'Test Migration' } };
const mockResult = { id: '1', name: 'Test Migration' };
migrationService.createMigrationHistory = jest.fn().mockResolvedValue(mockResult);
const result = await createMigrationHistory({}, mockInput, mockContext);
expect(migrationService.createMigrationHistory).toHaveBeenCalledWith(mockInput.migration);
expect(result).toEqual(mockResult);
});
});
describe('updateMigrationHistory', () => {
it('should update migration history successfully', async () => {
const mockInput = { migration: { id: '1', name: 'Updated Migration' } };
const mockResult = { id: '1', name: 'Updated Migration' };
migrationService.updateMigrationHistory = jest.fn().mockResolvedValue(mockResult);
const result = await updateMigrationHistory({}, mockInput, mockContext);
expect(migrationService.updateMigrationHistory).toHaveBeenCalledWith(mockInput.migration);
expect(result).toEqual(mockResult);
});
});
describe('setMigrationResult', () => {
it('should set migration result successfully', async () => {
const mockInput = { migrationId: '1', result: 'Success' };
const mockResult = { id: '1', result: 'Success' };
migrationService.setMigrationResult = jest.fn().mockResolvedValue(mockResult);
const result = await setMigrationResult({}, mockInput, mockContext);
expect(migrationService.setMigrationResult).toHaveBeenCalledWith(mockInput.migrationId, mockInput.result);
expect(result).toEqual(mockResult);
});
it('should throw an error if migrationId is missing', async () => {
const mockInput = { result: 'Success' };
await expect(setMigrationResult({}, mockInput, mockContext)).rejects.toThrow('Migration ID is required');
});
it('should throw an error if result is missing', async () => {
const mockInput = { migrationId: '1' };
await expect(setMigrationResult({}, mockInput, mockContext)).rejects.toThrow('Result is required');
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment