UNPKG

@jungvonmatt/sb-migrate

Version:

CLI tool for managing Storyblok schema and content migrations

86 lines 3.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const delete_1 = require("../../../handlers/datasource/delete"); const api_1 = require("../../../utils/api"); // Mock the API vitest_1.vi.mock("../../../utils/api", () => ({ api: { datasources: { get: vitest_1.vi.fn(), delete: vitest_1.vi.fn(), }, }, })); (0, vitest_1.describe)("handleDeleteDatasource", () => { const mockDatasource = { id: 123, name: "test-datasource", slug: "test-datasource", }; const mockMigration = { id: 123, }; const mockOptions = { isDryrun: false, }; (0, vitest_1.beforeEach)(() => { vitest_1.vi.clearAllMocks(); }); (0, vitest_1.it)("should delete a datasource successfully", async () => { // Arrange api_1.api.datasources.get.mockResolvedValue({ data: { datasource: mockDatasource }, }); api_1.api.datasources.delete.mockResolvedValue({}); // Act await (0, delete_1.handleDeleteDatasource)(mockMigration, mockOptions); // Assert (0, vitest_1.expect)(api_1.api.datasources.get).toHaveBeenCalledWith(123); (0, vitest_1.expect)(api_1.api.datasources.delete).toHaveBeenCalledWith(123); }); (0, vitest_1.it)("should handle dry run correctly", async () => { // Arrange const dryRunOptions = { isDryrun: true }; // Act await (0, delete_1.handleDeleteDatasource)(mockMigration, dryRunOptions); // Assert (0, vitest_1.expect)(api_1.api.datasources.get).not.toHaveBeenCalled(); (0, vitest_1.expect)(api_1.api.datasources.delete).not.toHaveBeenCalled(); }); (0, vitest_1.it)("should handle non-existent datasource gracefully", async () => { // Arrange api_1.api.datasources.get.mockResolvedValue({ data: { datasource: null }, }); // Act await (0, delete_1.handleDeleteDatasource)(mockMigration, mockOptions); // Assert (0, vitest_1.expect)(api_1.api.datasources.get).toHaveBeenCalledWith(123); (0, vitest_1.expect)(api_1.api.datasources.delete).not.toHaveBeenCalled(); }); (0, vitest_1.it)("should handle API errors gracefully", async () => { // Arrange const error = new Error("API Error"); api_1.api.datasources.get.mockRejectedValue(error); // Act await (0, delete_1.handleDeleteDatasource)(mockMigration, mockOptions); // Assert (0, vitest_1.expect)(api_1.api.datasources.get).toHaveBeenCalledWith(123); (0, vitest_1.expect)(api_1.api.datasources.delete).not.toHaveBeenCalled(); }); (0, vitest_1.it)("should handle delete errors gracefully", async () => { // Arrange api_1.api.datasources.get.mockResolvedValue({ data: { datasource: mockDatasource }, }); const error = new Error("Delete Error"); api_1.api.datasources.delete.mockRejectedValue(error); // Act await (0, delete_1.handleDeleteDatasource)(mockMigration, mockOptions); // Assert (0, vitest_1.expect)(api_1.api.datasources.get).toHaveBeenCalledWith(123); (0, vitest_1.expect)(api_1.api.datasources.delete).toHaveBeenCalledWith(123); }); }); //# sourceMappingURL=delete.test.js.map