Created
August 27, 2024 15:54
-
-
Save brian-lim-42/5357b34827b29010f687167599333820 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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