Update typing to specify that path or name must be passed (#796)

This commit is contained in:
Justin Dalrymple 2020-05-16 13:33:03 +02:00 committed by GitHub
parent f3638aecfa
commit 1cec2d736c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 7 deletions

View File

@ -61,7 +61,10 @@ export class Projects extends BaseService {
return RequestHelper.post(this, `projects/${pId}/archive`, options);
}
create({ userId, ...options }: { userId?: number } & BaseRequestOptions) {
create({
userId,
...options
}: ({ name: string } | { path: string }) & { userId?: number } & BaseRequestOptions) {
const url = userId ? `projects/user/${encodeURIComponent(userId)}` : 'projects';
return RequestHelper.post(this, url, options);

View File

@ -56,28 +56,28 @@ describe('Projects.archive', () => {
describe('Projects.create', () => {
it('should request POST /projects when userId undefined', async () => {
await service.create({ title: 'test proj' });
await service.create({ name: 'test proj' });
expect(RequestHelper.post).toHaveBeenCalledWith(service, 'projects', {
title: 'test proj',
name: 'test proj',
});
});
it('should request POST /projects/user/:id when userId defined', async () => {
await service.create({ userId: 2, title: 'test proj' });
await service.create({ userId: 2, name: 'test proj' });
expect(RequestHelper.post).toHaveBeenCalledWith(service, 'projects/user/2', {
title: 'test proj',
name: 'test proj',
});
});
});
describe('Projects.edit', () => {
it('should request PUT /projects', async () => {
await service.edit(12, { title: 'test proj 2' });
await service.edit(12, { name: 'test proj 2' });
expect(RequestHelper.put).toHaveBeenCalledWith(service, 'projects/12', {
title: 'test proj 2',
name: 'test proj 2',
});
});
});