-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from HF6-PROJECT/ara-14
feat: Added item endpoint, to get item with extra data (Folder, Blob,…
- Loading branch information
Showing
16 changed files
with
910 additions
and
42 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
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,173 @@ | ||
import { User } from '@prisma/client'; | ||
import UserService from '../../auth/user.service'; | ||
import FolderService from '../folder/folder.service'; | ||
import AuthService from '../../auth/auth.service'; | ||
import BlobService from '../blob/blob.service'; | ||
|
||
describe('GET /api/item/:parentId', () => { | ||
let userService: UserService; | ||
let folderService: FolderService; | ||
let authService: AuthService; | ||
let blobService: BlobService; | ||
|
||
let user: User; | ||
let otherUser: User; | ||
|
||
beforeAll(async () => { | ||
userService = new UserService(); | ||
folderService = new FolderService(); | ||
authService = new AuthService(); | ||
blobService = new BlobService(); | ||
|
||
user = await userService.createUser({ | ||
name: 'Joe Biden the 1st', | ||
email: '[email protected]', | ||
password: '1234', | ||
}); | ||
otherUser = await userService.createUser({ | ||
name: 'Joe Biden the 2nd', | ||
email: '[email protected]', | ||
password: '4321', | ||
}); | ||
}); | ||
|
||
it('Should return status 200 and all items from parentId', async () => { | ||
const { accessToken } = await authService.createTokens(user.id); | ||
|
||
const parentFolder = await folderService.createFolder({ | ||
name: 'Folder1', | ||
color: '#123456', | ||
ownerId: user.id, | ||
parentId: null, | ||
}); | ||
|
||
await blobService.createBlob({ | ||
mimeType: 'text/plain', | ||
name: 'test1.txt', | ||
ownerId: user.id, | ||
parentId: parentFolder.id, | ||
blobUrl: 'https://example.com/test1.txt', | ||
}); | ||
|
||
await folderService.createFolder({ | ||
name: 'Folder2', | ||
color: '#987654', | ||
ownerId: user.id, | ||
parentId: parentFolder.id, | ||
}); | ||
|
||
const response = await global.fastify.inject({ | ||
method: 'GET', | ||
url: '/api/item/' + parentFolder.id, | ||
headers: { | ||
authorization: 'Bearer ' + accessToken, | ||
}, | ||
}); | ||
|
||
expect(response.statusCode).toBe(200); | ||
expect(response.json()).toEqual([ | ||
{ | ||
id: expect.any(Number), | ||
name: 'test1.txt', | ||
blobUrl: 'https://example.com/test1.txt', | ||
parentId: parentFolder.id, | ||
ownerId: user.id, | ||
mimeType: 'text/plain', | ||
createdAt: expect.any(String), | ||
deletedAt: null, | ||
updatedAt: expect.any(String), | ||
}, | ||
{ | ||
id: expect.any(Number), | ||
name: 'Folder2', | ||
color: '#987654', | ||
parentId: parentFolder.id, | ||
ownerId: user.id, | ||
mimeType: 'application/vnd.cloudstore.folder', | ||
createdAt: expect.any(String), | ||
deletedAt: null, | ||
updatedAt: expect.any(String), | ||
}, | ||
]); | ||
}); | ||
|
||
it('Should return status 401, when unauthorized', async () => { | ||
const parentFolder = await folderService.createFolder({ | ||
name: 'Folder1', | ||
color: '#123456', | ||
ownerId: user.id, | ||
parentId: null, | ||
}); | ||
|
||
await blobService.createBlob({ | ||
mimeType: 'text/plain', | ||
name: 'test1.txt', | ||
ownerId: user.id, | ||
parentId: parentFolder.id, | ||
blobUrl: 'https://example.com/test1.txt', | ||
}); | ||
await folderService.createFolder({ | ||
name: 'Folder2', | ||
color: '#987654', | ||
ownerId: user.id, | ||
parentId: parentFolder.id, | ||
}); | ||
|
||
const response = await global.fastify.inject({ | ||
method: 'GET', | ||
url: '/api/item/' + parentFolder.id, | ||
headers: { | ||
authorization: 'WrongAuth!', | ||
}, | ||
}); | ||
|
||
expect(response.statusCode).toBe(401); | ||
expect(response.json()).toEqual({ | ||
error: 'UnauthorizedError', | ||
errors: { | ||
_: ['Unauthorized'], | ||
}, | ||
statusCode: 401, | ||
}); | ||
}); | ||
|
||
it('Should return status 401, when unauthorized to the parent folder', async () => { | ||
const { accessToken } = await authService.createTokens(otherUser.id); | ||
const parentFolder = await folderService.createFolder({ | ||
name: 'Folder1', | ||
color: '#123456', | ||
ownerId: user.id, | ||
parentId: null, | ||
}); | ||
await blobService.createBlob({ | ||
mimeType: 'text/plain', | ||
name: 'test1.txt', | ||
ownerId: user.id, | ||
parentId: parentFolder.id, | ||
blobUrl: 'https://example.com/test1.txt', | ||
}); | ||
await folderService.createFolder({ | ||
name: 'Folder2', | ||
color: '#987654', | ||
ownerId: user.id, | ||
parentId: parentFolder.id, | ||
}); | ||
|
||
const response = await global.fastify.inject({ | ||
method: 'GET', | ||
url: '/api/item/' + parentFolder.id, | ||
headers: { | ||
authorization: 'Bearer ' + accessToken, | ||
}, | ||
}); | ||
|
||
expect(response.statusCode).toBe(401); | ||
expect(response.json()).toEqual({ | ||
error: 'UnauthorizedError', | ||
errors: { | ||
_: ['Unauthorized'], | ||
}, | ||
statusCode: 401, | ||
}); | ||
}); | ||
}); |
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,137 @@ | ||
import { User } from '@prisma/client'; | ||
import UserService from '../../auth/user.service'; | ||
import FolderService from '../folder/folder.service'; | ||
import AuthService from '../../auth/auth.service'; | ||
import BlobService from '../blob/blob.service'; | ||
|
||
describe('GET /api/item', () => { | ||
let userService: UserService; | ||
let folderService: FolderService; | ||
let authService: AuthService; | ||
let blobService: BlobService; | ||
|
||
let user: User; | ||
|
||
beforeAll(async () => { | ||
userService = new UserService(); | ||
folderService = new FolderService(); | ||
authService = new AuthService(); | ||
blobService = new BlobService(); | ||
|
||
user = await userService.createUser({ | ||
name: 'Joe Biden the 1st', | ||
email: '[email protected]', | ||
password: '1234', | ||
}); | ||
}); | ||
|
||
it('Should return status 200 and all items from root folder', async () => { | ||
const { accessToken } = await authService.createTokens(user.id); | ||
|
||
await blobService.createBlob({ | ||
mimeType: 'text/plain', | ||
name: 'test1.txt', | ||
ownerId: user.id, | ||
parentId: null, | ||
blobUrl: 'https://example.com/test1.txt', | ||
}); | ||
|
||
await folderService.createFolder({ | ||
name: 'Folder1', | ||
color: '#123456', | ||
ownerId: user.id, | ||
parentId: null, | ||
}); | ||
await folderService.createFolder({ | ||
name: 'Folder2', | ||
color: '#987654', | ||
ownerId: user.id, | ||
parentId: null, | ||
}); | ||
|
||
const response = await global.fastify.inject({ | ||
method: 'GET', | ||
url: '/api/item', | ||
headers: { | ||
authorization: 'Bearer ' + accessToken, | ||
}, | ||
}); | ||
|
||
expect(response.statusCode).toBe(200); | ||
expect(response.json()).toEqual([ | ||
{ | ||
id: expect.any(Number), | ||
name: 'test1.txt', | ||
blobUrl: 'https://example.com/test1.txt', | ||
parentId: null, | ||
ownerId: user.id, | ||
mimeType: 'text/plain', | ||
createdAt: expect.any(String), | ||
deletedAt: null, | ||
updatedAt: expect.any(String), | ||
}, | ||
{ | ||
id: expect.any(Number), | ||
name: 'Folder1', | ||
color: '#123456', | ||
parentId: null, | ||
ownerId: user.id, | ||
mimeType: 'application/vnd.cloudstore.folder', | ||
createdAt: expect.any(String), | ||
deletedAt: null, | ||
updatedAt: expect.any(String), | ||
}, | ||
{ | ||
id: expect.any(Number), | ||
name: 'Folder2', | ||
color: '#987654', | ||
parentId: null, | ||
ownerId: user.id, | ||
mimeType: 'application/vnd.cloudstore.folder', | ||
createdAt: expect.any(String), | ||
deletedAt: null, | ||
updatedAt: expect.any(String), | ||
}, | ||
]); | ||
}); | ||
|
||
it('Should return status 401, when unauthorized', async () => { | ||
await blobService.createBlob({ | ||
mimeType: 'text/plain', | ||
name: 'test1.txt', | ||
ownerId: user.id, | ||
parentId: null, | ||
blobUrl: 'https://example.com/test1.txt', | ||
}); | ||
|
||
await folderService.createFolder({ | ||
name: 'Folder1', | ||
color: '#123456', | ||
ownerId: user.id, | ||
parentId: null, | ||
}); | ||
await folderService.createFolder({ | ||
name: 'Folder2', | ||
color: '#987654', | ||
ownerId: user.id, | ||
parentId: null, | ||
}); | ||
|
||
const response = await global.fastify.inject({ | ||
method: 'GET', | ||
url: '/api/item', | ||
headers: { | ||
authorization: 'WrongAuth!', | ||
}, | ||
}); | ||
|
||
expect(response.statusCode).toBe(401); | ||
expect(response.json()).toEqual({ | ||
error: 'UnauthorizedError', | ||
errors: { | ||
_: ['Unauthorized'], | ||
}, | ||
statusCode: 401, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.