-
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.
- Loading branch information
1 parent
25866c5
commit 05d1b68
Showing
7 changed files
with
449 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import { User } from '@prisma/client'; | ||
import UserService from '../../auth/user.service'; | ||
import FolderService from '../folder/folder.service'; | ||
import AuthService from '../../auth/auth.service'; | ||
|
||
// The tests can only be run with folder - Since the blob service has istanbul ignore next | ||
describe('GET /api/item/:parentId', () => { | ||
let userService: UserService; | ||
let folderService: FolderService; | ||
let authService: AuthService; | ||
|
||
let user: User; | ||
let otherUser: User; | ||
|
||
beforeAll(async () => { | ||
userService = new UserService(); | ||
folderService = new FolderService(); | ||
authService = new AuthService(); | ||
|
||
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('All items should from the folder, with the given parentId', async () => { | ||
const { accessToken } = await authService.createTokens(user.id); | ||
|
||
const parentFolder = await folderService.createFolder({ | ||
name: 'Folder1', | ||
color: '#123456', | ||
ownerId: user.id, | ||
parentId: null, | ||
}); | ||
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: '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('Getting items should return error, if auth is not set', async () => { | ||
const parentFolder = await folderService.createFolder({ | ||
name: 'Folder1', | ||
color: '#123456', | ||
ownerId: user.id, | ||
parentId: null, | ||
}); | ||
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('Getting items should return error, if you do not have access 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 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,108 @@ | ||
import { User } from '@prisma/client'; | ||
import UserService from '../../auth/user.service'; | ||
import FolderService from '../folder/folder.service'; | ||
import AuthService from '../../auth/auth.service'; | ||
|
||
// The tests can only be run with folder - Since the blob service has istanbul ignore next | ||
describe('GET /api/item', () => { | ||
let userService: UserService; | ||
let folderService: FolderService; | ||
let authService: AuthService; | ||
|
||
let user: User; | ||
|
||
beforeAll(async () => { | ||
userService = new UserService(); | ||
folderService = new FolderService(); | ||
authService = new AuthService(); | ||
|
||
user = await userService.createUser({ | ||
name: 'Joe Biden the 1st', | ||
email: '[email protected]', | ||
password: '1234', | ||
}); | ||
}); | ||
|
||
it('All items should be returned from the users root "folder"', async () => { | ||
const { accessToken } = await authService.createTokens(user.id); | ||
|
||
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: '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('Getting root items should return error, if auth is not set', async () => { | ||
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.