This repository has been archived by the owner on Dec 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gallery, account, album, image): implement delete actions
scope: client
- Loading branch information
Showing
22 changed files
with
232 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import unblock from '../unblock'; | ||
|
||
const mockGet = jest.fn(); | ||
const MockClient = jest.fn().mockImplementation(() => { | ||
return { | ||
delete: mockGet, | ||
}; | ||
}); | ||
|
||
beforeEach(() => { | ||
MockClient.mockClear(); | ||
mockGet.mockClear(); | ||
}); | ||
|
||
test('unblock calls the correct endpoint and resolves', () => { | ||
const mockResponse = '{"success":true}'; | ||
mockGet.mockReturnValueOnce(Promise.resolve(mockResponse)); | ||
const promiseResponse = unblock(new MockClient(), 'john'); | ||
expect(promiseResponse).resolves.toBe(mockResponse); | ||
expect(mockGet).toHaveBeenCalledTimes(1); | ||
expect(mockGet).toHaveBeenCalledWith( | ||
'https://api.imgur.com/account/v1/john/block', | ||
'GET', | ||
); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './generateAccessToken'; | ||
export * from './getSettings'; | ||
export * from './unblock'; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Client } from '../client'; | ||
import { ImgurApiResponse, AuthenticationRequiredResponse } from '../responses'; | ||
import { createUnblockUrl } from '../helpers/'; | ||
|
||
export default async function unblock( | ||
client: Client, | ||
username: string, | ||
): Promise<ImgurApiResponse | AuthenticationRequiredResponse> { | ||
return client.delete(`${createUnblockUrl(username)}`, 'GET'); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Client } from '../client'; | ||
import { ImgurApiResponse, AuthenticationRequiredResponse } from '../responses'; | ||
import { UNFOLLOW_TAG_URI } from '../endpoints'; | ||
|
||
export default async function unfollowTag( | ||
client: Client, | ||
tagName: string, | ||
): Promise<ImgurApiResponse | AuthenticationRequiredResponse> { | ||
return client.delete(`${UNFOLLOW_TAG_URI}/${tagName}`); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import deleteAlbum from '../delete'; | ||
|
||
const mockDelete = jest.fn(); | ||
const MockClient = jest.fn().mockImplementation(() => { | ||
return { | ||
delete: mockDelete, | ||
}; | ||
}); | ||
|
||
beforeEach(() => { | ||
MockClient.mockClear(); | ||
mockDelete.mockClear(); | ||
}); | ||
|
||
const mockAlbumHash = `fc1f5de1-f8dc-4ba7-9f17-52ab9ad8c46c`; | ||
|
||
test('deleteAlbum calls the correct endpoint and resolves', () => { | ||
const mockResponse = '{"success":true}'; | ||
mockDelete.mockReturnValueOnce(Promise.resolve(mockResponse)); | ||
const promiseResponse = deleteAlbum(new MockClient(), mockAlbumHash); | ||
expect(promiseResponse).resolves.toBe(mockResponse); | ||
expect(mockDelete).toHaveBeenCalledTimes(1); | ||
expect(mockDelete).toHaveBeenCalledWith( | ||
`https://api.imgur.com/3/album/${mockAlbumHash}`, | ||
); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Client } from '../client'; | ||
import { ImgurApiResponse, AuthenticationRequiredResponse } from '../responses'; | ||
import { DELETE_ALBUM_URI } from '../endpoints'; | ||
|
||
export default async function deleteAlbum( | ||
client: Client, | ||
albumHash: string, | ||
): Promise<ImgurApiResponse | AuthenticationRequiredResponse> { | ||
return client.delete(`${DELETE_ALBUM_URI}${albumHash}`); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './delete'; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import deleteComment from '../delete'; | ||
|
||
const mockDelete = jest.fn(); | ||
const MockClient = jest.fn().mockImplementation(() => { | ||
return { | ||
delete: mockDelete, | ||
}; | ||
}); | ||
|
||
beforeEach(() => { | ||
MockClient.mockClear(); | ||
mockDelete.mockClear(); | ||
}); | ||
|
||
test('deleteComment calls the correct endpoint and resolves', () => { | ||
const mockResponse = '{"success":true}'; | ||
mockDelete.mockReturnValueOnce(Promise.resolve(mockResponse)); | ||
|
||
const promiseResponse = deleteComment(new MockClient(), '1234'); | ||
expect(promiseResponse).resolves.toBe(mockResponse); | ||
expect(mockDelete).toHaveBeenCalledTimes(1); | ||
expect(mockDelete).toHaveBeenCalledWith( | ||
'https://api.imgur.com/3/comment/1234', | ||
); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Client } from '../client'; | ||
import { ImgurApiResponse, AuthenticationRequiredResponse } from '../responses'; | ||
import { DELETE_COMMENT_URI } from '../endpoints'; | ||
|
||
export default async function deleteComment( | ||
client: Client, | ||
commentId: string, | ||
): Promise<ImgurApiResponse | AuthenticationRequiredResponse> { | ||
return client.delete(`${DELETE_COMMENT_URI}${commentId}`); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './delete'; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
export const ACCESS_TOKEN_URI = 'https://api.imgur.com/oauth2/token'; | ||
export const UPLOAD_URI = 'https://api.imgur.com/3/upload'; | ||
export const ACCOUNT_SETTINGS = 'https://api.imgur.com/3/account/me/settings'; | ||
export const DELETE_IMAGE_URI = 'https://api.imgur.com/3/image/'; | ||
export const DELETE_ALBUM_URI = 'https://api.imgur.com/3/album/'; | ||
export const DELETE_IMAGE_FROM_GALLERY_URI = 'https://api.imgur.com/3/gallery/'; | ||
export const ACCOUNT_URI = 'https://api.imgur.com/account/v1/'; | ||
export const UNFOLLOW_TAG_URI = | ||
'https://api.imgur.com/3/account/me/follow/tag/'; | ||
export const DELETE_COMMENT_URI = 'https://api.imgur.com/3/comment/'; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import deleteFromGallery from '../delete'; | ||
|
||
const mockDelete = jest.fn(); | ||
const MockClient = jest.fn().mockImplementation(() => { | ||
return { | ||
delete: mockDelete, | ||
}; | ||
}); | ||
|
||
beforeEach(() => { | ||
MockClient.mockClear(); | ||
mockDelete.mockClear(); | ||
}); | ||
|
||
test('deleteFromGallery calls the correct endpoint and resolves', () => { | ||
const mockResponse = '{"success":true}'; | ||
mockDelete.mockReturnValueOnce(Promise.resolve(mockResponse)); | ||
const mockGalleryHash = '37ad6e9a-7995-4042-a179-0380b7291497'; | ||
const promiseResponse = deleteFromGallery(new MockClient(), mockGalleryHash); | ||
expect(promiseResponse).resolves.toBe(mockResponse); | ||
expect(mockDelete).toHaveBeenCalledTimes(1); | ||
expect(mockDelete).toHaveBeenCalledWith( | ||
`https://api.imgur.com/3/gallery/${mockGalleryHash}`, | ||
); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Client } from '../client'; | ||
import { ImgurApiResponse, AuthenticationRequiredResponse } from '../responses'; | ||
import { DELETE_IMAGE_FROM_GALLERY_URI } from '../endpoints'; | ||
|
||
export default async function deleteFromGallery( | ||
client: Client, | ||
galleryHash: string, | ||
): Promise<ImgurApiResponse | AuthenticationRequiredResponse> { | ||
return client.delete(`${DELETE_IMAGE_FROM_GALLERY_URI}${galleryHash}`); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './delete'; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import createUnblockUrl from '../createUnblockUrl'; | ||
|
||
test('createUnblockUrl returns a constructed unblock url', () => { | ||
const unblockUrl = createUnblockUrl('john'); | ||
expect(unblockUrl).toBe('https://api.imgur.com/account/v1/john/block'); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ACCOUNT_URI } from '../endpoints'; | ||
|
||
/** | ||
* Accepts username of account to | ||
* be unblocked and returns the constructed unblocked URL endpoint | ||
* | ||
* @param username | ||
* @returns https://api.imgur.com/account/v1/{{username}}/block | ||
*/ | ||
|
||
const createUnblockUrl = (username: string) => { | ||
return `${ACCOUNT_URI}${username}/block`; | ||
}; | ||
|
||
export default createUnblockUrl; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import createUnblockUrl from './createUnblockUrl'; | ||
import createForm from './createForm'; | ||
|
||
export { createUnblockUrl, createForm }; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Client } from '../client'; | ||
import { PathLike } from 'fs'; | ||
import { DELETE_IMAGE_URI } from '../endpoints'; | ||
import { ImgurApiResponse, AuthenticationRequiredResponse } from '../responses'; | ||
|
||
type ImageHash = PathLike; | ||
|
||
export default async function deleteImage( | ||
client: Client, | ||
imageHash: ImageHash, | ||
): Promise<ImgurApiResponse | AuthenticationRequiredResponse> { | ||
return client.delete(`${DELETE_IMAGE_URI}/${imageHash}`); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './upload'; | ||
export * from './delete'; |