Skip to content

Commit 5f98090

Browse files
committed
Add DELETE method support in mockRequest and test for removeStar functionality
1 parent ab1cbd3 commit 5f98090

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

test/mock.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let undiciInterceptable: Interceptable;
1010
type BodyMatcher = (body: string | Record<string, any>) => boolean;
1111

1212
interface MockParams {
13-
method: "GET" | "POST";
13+
method: "GET" | "POST" | "DELETE";
1414
path: string;
1515
query?: Record<string, any>;
1616
body?: BodyMatcher;
@@ -42,6 +42,8 @@ export const mockRequest = ({
4242
interceptor = nockScope.get(newPath);
4343
} else if (method === "POST" ) {
4444
interceptor = nockScope.post(newPath, body);
45+
} else if (method === "DELETE") {
46+
interceptor = nockScope.delete(newPath);
4547
}
4648

4749
interceptor

test/test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,4 +299,23 @@ describe("Backlog API", () => {
299299
throw err
300300
});
301301
});
302+
303+
it('should remove star.', (done) => {
304+
const starId = 123;
305+
mockRequest({
306+
method: "DELETE",
307+
path: `/api/v2/stars/${starId}`,
308+
query: { apiKey },
309+
status: 204,
310+
data: [],
311+
times: 1,
312+
});
313+
backlog.removeStar(starId).then(data => {
314+
// Should resolve without error and without any value
315+
assert(data === undefined);
316+
done();
317+
}).catch(err => {
318+
throw err;
319+
});
320+
});
302321
});

0 commit comments

Comments
 (0)