-
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
158f5ca
commit 6cbbca5
Showing
15 changed files
with
1,281 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
prisma/migrations/20231003122910_item_folder/migration.sql
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,32 @@ | ||
-- DropForeignKey | ||
ALTER TABLE "ItemBlob" DROP CONSTRAINT "ItemBlob_itemId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "ItemSharing" DROP CONSTRAINT "ItemSharing_itemId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "ItemSharing" DROP CONSTRAINT "ItemSharing_userId_fkey"; | ||
|
||
-- CreateTable | ||
CREATE TABLE "ItemFolder" ( | ||
"id" SERIAL NOT NULL, | ||
"color" VARCHAR(255) NOT NULL, | ||
"itemId" INTEGER NOT NULL, | ||
|
||
CONSTRAINT "ItemFolder_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "ItemFolder_itemId_key" ON "ItemFolder"("itemId"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "ItemFolder" ADD CONSTRAINT "ItemFolder_itemId_fkey" FOREIGN KEY ("itemId") REFERENCES "Item"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "ItemBlob" ADD CONSTRAINT "ItemBlob_itemId_fkey" FOREIGN KEY ("itemId") REFERENCES "Item"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "ItemSharing" ADD CONSTRAINT "ItemSharing_itemId_fkey" FOREIGN KEY ("itemId") REFERENCES "Item"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "ItemSharing" ADD CONSTRAINT "ItemSharing_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
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
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,159 @@ | ||
import { User } from '@prisma/client'; | ||
import UserService from '../../../auth/user.service'; | ||
import AuthService from '../../../auth/auth.service'; | ||
import FolderService from '../folder.service'; | ||
|
||
describe('POST /api/folder', () => { | ||
let userService: UserService; | ||
let authService: AuthService; | ||
let folderService: FolderService; | ||
|
||
let user: User; | ||
let otherUser: User; | ||
|
||
beforeAll(async () => { | ||
authService = new AuthService(); | ||
userService = new UserService(); | ||
folderService = new FolderService(); | ||
|
||
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 folder', async () => { | ||
const { accessToken } = await authService.createTokens(user.id); | ||
|
||
const response = await global.fastify.inject({ | ||
method: 'POST', | ||
url: '/api/folder', | ||
headers: { | ||
authorization: 'Bearer ' + accessToken, | ||
}, | ||
payload: { | ||
name: 'Folder Name', | ||
color: '#78BC61', | ||
}, | ||
}); | ||
|
||
expect(response.statusCode).toBe(200); | ||
expect(response.json()).toEqual({ | ||
id: expect.any(Number), | ||
name: 'Folder Name', | ||
color: '#78BC61', | ||
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 () => { | ||
const response = await global.fastify.inject({ | ||
method: 'POST', | ||
url: '/api/folder', | ||
headers: { | ||
authorization: 'invalid_access_token!!!', | ||
}, | ||
payload: { | ||
name: 'Folder Name', | ||
color: '#78BC61', | ||
parentId: null, | ||
}, | ||
}); | ||
|
||
expect(response.statusCode).toBe(401); | ||
expect(response.json()).toEqual({ | ||
error: 'UnauthorizedError', | ||
errors: { | ||
_: ['Unauthorized'], | ||
}, | ||
statusCode: 401, | ||
}); | ||
}); | ||
|
||
it('should return status 401, when folder name is not provided', async () => { | ||
const { accessToken } = await authService.createTokens(user.id); | ||
|
||
const response = await global.fastify.inject({ | ||
method: 'POST', | ||
url: '/api/folder', | ||
headers: { | ||
authorization: 'Bearer ' + accessToken, | ||
}, | ||
payload: { | ||
color: '#78BC61', | ||
parentId: null, | ||
}, | ||
}); | ||
|
||
expect(response.statusCode).toBe(400); | ||
expect(response.json()).toEqual({ | ||
error: 'ValidationError', | ||
errors: { | ||
_: ['Name is required'], | ||
}, | ||
statusCode: 400, | ||
}); | ||
}); | ||
|
||
it('should return status 401, when folder color is not provided', async () => { | ||
const { accessToken } = await authService.createTokens(user.id); | ||
|
||
const response = await global.fastify.inject({ | ||
method: 'POST', | ||
url: '/api/folder', | ||
headers: { | ||
authorization: 'Bearer ' + accessToken, | ||
}, | ||
payload: { | ||
name: 'Folder name', | ||
parentId: null, | ||
}, | ||
}); | ||
|
||
expect(response.statusCode).toBe(400); | ||
expect(response.json()).toEqual({ | ||
error: 'ValidationError', | ||
errors: { | ||
_: ['Color is required'], | ||
}, | ||
statusCode: 400, | ||
}); | ||
}); | ||
|
||
it("should return status 400, when parent id isn't a number", async () => { | ||
const { accessToken } = await authService.createTokens(user.id); | ||
|
||
const response = await global.fastify.inject({ | ||
method: 'POST', | ||
url: '/api/folder', | ||
headers: { | ||
authorization: 'Bearer ' + accessToken, | ||
}, | ||
payload: { | ||
name: 'Folder Name', | ||
color: '#78BC61', | ||
parentId: 'invalid_id', | ||
}, | ||
}); | ||
|
||
expect(response.statusCode).toBe(400); | ||
expect(response.json()).toEqual({ | ||
error: 'ValidationError', | ||
errors: { | ||
parentId: ['Item id must be a number'], | ||
}, | ||
statusCode: 400, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.