delete.test.ts•2.9 kB
import { jest, /*expect,*/ describe, it, beforeEach } from '@jest/globals';
import type { Mock } from 'jest-mock';
import { IssuesClient } from '../../../client/issues.js';
// import { mockResponse, mockErrorResponse } from '../../helpers/mocks.js'; // Unused
// import * as fixtures from '../../helpers/fixtures.js'; // Unused
// import config from '../../../config.js'; // Unused
// import { RedmineApiError } from '../../../client/base.js'; // Unused
// import { parseUrl } from '../../helpers/url.js'; // Unused
describe("Issues API (DELETE)", () => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
let client: IssuesClient;
let mockFetch: Mock;
// const issueId = fixtures.singleIssueResponse.issue.id; // Unused
beforeEach(() => {
client = new IssuesClient(); // client is assigned but never used in the current test structure
mockFetch = jest.spyOn(global, "fetch") as Mock;
mockFetch.mockReset();
});
describe("DELETE /issues/:id.json (deleteIssue)", () => {
// DELETE操作のテストは安全のためスキップ
it.skip("all DELETE operation tests are skipped for safety", () => {
// DELETE操作のテストはAPIに影響を与えるため、実際の実行は避けるべき。
// もしテストを書く場合は、モックサーバーを使用するか、
// Redmine APIの仕様に基づきDELETEリクエストが204 No Contentを返すことを確認する。
// - ステータスコード
// - ヘッダー内容(例:X-Request-Idなど特定のIDが返るか)
// - ボディが空であること
// - エラーハンドリング(例:存在しないIDを削除しようとした場合など)
//
// 以下にテストの雛形を示すが、実行は推奨しない。
// 実際のテストではモックサーバーで挙動を定義し、APIコール結果を確認することが望ましい。
});
});
});
// Example of how a test might look if it were enabled:
/*
it("deletes an issue successfully", async () => {
// Arrange
const issueIdToDelete = 123;
mockFetch.mockImplementationOnce(() =>
Promise.resolve(new Response(null, { status: 204 }))
);
// Act
await client.deleteIssue(issueIdToDelete);
// Assert
expect(mockFetch).toHaveBeenCalledWith(
`${config.redmineUrl}/issues/${issueIdToDelete}.json`,
expect.objectContaining({
method: "DELETE",
headers: expect.objectContaining({
"X-Redmine-API-Key": config.apiKey,
}),
})
);
});
it("handles error when issue to delete is not found", async () => {
// Arrange
const issueIdToDelete = 999;
mockFetch.mockImplementationOnce(() =>
Promise.resolve(mockErrorResponse(404, ["Issue not found"]))
);
// Act & Assert
await expect(client.deleteIssue(issueIdToDelete)).rejects.toThrow(RedmineApiError);
});
*/