fix: update dependencies to latest

This commit is contained in:
2023-07-22 16:26:27 +02:00
parent 23d2a9da71
commit 9a1684e22b
123 changed files with 2322 additions and 5765 deletions

View File

@@ -1,18 +1,20 @@
import tap from 'tap'
import test from 'node:test'
import assert from 'node:assert/strict'
import sinon from 'sinon'
import { application } from '../../../../application.js'
import { authenticateUserTest } from '../../../../__test__/utils/authenticateUserTest.js'
import prisma from '../../../../tools/database/prisma.js'
import { channelExample } from '../../../../models/Channel.js'
import { memberExample } from '../../../../models/Member.js'
import { application } from '#src/application.js'
import { authenticateUserTest } from '#src/__test__/utils/authenticateUserTest.js'
import prisma from '#src/tools/database/prisma.js'
import { channelExample } from '#src/models/Channel.js'
import { memberExample } from '#src/models/Member.js'
await tap.test('DELETE /channels/[channelId]', async (t) => {
await test('DELETE /channels/[channelId]', async (t) => {
t.afterEach(() => {
sinon.restore()
})
await t.test('succeeds', async (t) => {
await t.test('succeeds', async () => {
const defaultChannelId = 5
const { accessToken } = await authenticateUserTest()
sinon.stub(prisma, 'channel').value({
@@ -45,14 +47,14 @@ await tap.test('DELETE /channels/[channelId]', async (t) => {
}
})
const responseJson = response.json()
t.equal(response.statusCode, 200)
t.equal(responseJson.id, channelExample.id)
t.equal(responseJson.name, channelExample.name)
t.equal(responseJson.guildId, channelExample.guildId)
t.equal(responseJson.defaultChannelId, defaultChannelId)
assert.strictEqual(response.statusCode, 200)
assert.strictEqual(responseJson.id, channelExample.id)
assert.strictEqual(responseJson.name, channelExample.name)
assert.strictEqual(responseJson.guildId, channelExample.guildId)
assert.strictEqual(responseJson.defaultChannelId, defaultChannelId)
})
await t.test('fails if there is only one channel', async (t) => {
await t.test('fails if there is only one channel', async () => {
const { accessToken } = await authenticateUserTest()
sinon.stub(prisma, 'channel').value({
findUnique: async () => {
@@ -74,10 +76,10 @@ await tap.test('DELETE /channels/[channelId]', async (t) => {
authorization: `Bearer ${accessToken}`
}
})
t.equal(response.statusCode, 400)
assert.strictEqual(response.statusCode, 400)
})
await t.test('fails if the channel is not found', async (t) => {
await t.test('fails if the channel is not found', async () => {
const { accessToken } = await authenticateUserTest()
sinon.stub(prisma, 'channel').value({
findUnique: async () => {
@@ -91,10 +93,10 @@ await tap.test('DELETE /channels/[channelId]', async (t) => {
authorization: `Bearer ${accessToken}`
}
})
t.equal(response.statusCode, 404)
assert.strictEqual(response.statusCode, 404)
})
await t.test('fails if the member is not found', async (t) => {
await t.test('fails if the member is not found', async () => {
const { accessToken } = await authenticateUserTest()
sinon.stub(prisma, 'channel').value({
findUnique: async () => {
@@ -113,10 +115,10 @@ await tap.test('DELETE /channels/[channelId]', async (t) => {
authorization: `Bearer ${accessToken}`
}
})
t.equal(response.statusCode, 404)
assert.strictEqual(response.statusCode, 404)
})
await t.test('fails if the member is not owner', async (t) => {
await t.test('fails if the member is not owner', async () => {
const { accessToken } = await authenticateUserTest()
sinon.stub(prisma, 'channel').value({
findUnique: async () => {
@@ -138,6 +140,6 @@ await tap.test('DELETE /channels/[channelId]', async (t) => {
authorization: `Bearer ${accessToken}`
}
})
t.equal(response.statusCode, 400)
assert.strictEqual(response.statusCode, 400)
})
})

View File

@@ -1,18 +1,20 @@
import tap from 'tap'
import test from 'node:test'
import assert from 'node:assert/strict'
import sinon from 'sinon'
import { application } from '../../../../application.js'
import { authenticateUserTest } from '../../../../__test__/utils/authenticateUserTest.js'
import prisma from '../../../../tools/database/prisma.js'
import { channelExample } from '../../../../models/Channel.js'
import { memberExample } from '../../../../models/Member.js'
import { application } from '#src/application.js'
import { authenticateUserTest } from '#src/__test__/utils/authenticateUserTest.js'
import prisma from '#src/tools/database/prisma.js'
import { channelExample } from '#src/models/Channel.js'
import { memberExample } from '#src/models/Member.js'
await tap.test('GET /channels/[channelId]', async (t) => {
await test('GET /channels/[channelId]', async (t) => {
t.afterEach(() => {
sinon.restore()
})
await t.test('succeeds', async (t) => {
await t.test('succeeds', async () => {
const { accessToken } = await authenticateUserTest()
sinon.stub(prisma, 'channel').value({
findUnique: async () => {
@@ -32,13 +34,13 @@ await tap.test('GET /channels/[channelId]', async (t) => {
}
})
const responseJson = response.json()
t.equal(response.statusCode, 200)
t.equal(responseJson.channel.id, channelExample.id)
t.equal(responseJson.channel.name, channelExample.name)
t.equal(responseJson.channel.guildId, channelExample.guildId)
assert.strictEqual(response.statusCode, 200)
assert.strictEqual(responseJson.channel.id, channelExample.id)
assert.strictEqual(responseJson.channel.name, channelExample.name)
assert.strictEqual(responseJson.channel.guildId, channelExample.guildId)
})
await t.test('fails with not found member', async (t) => {
await t.test('fails with not found member', async () => {
const { accessToken } = await authenticateUserTest()
sinon.stub(prisma, 'channel').value({
findUnique: async () => {
@@ -58,11 +60,11 @@ await tap.test('GET /channels/[channelId]', async (t) => {
}
})
const responseJson = response.json()
t.equal(response.statusCode, 404)
t.equal(responseJson.message, 'Channel not found')
assert.strictEqual(response.statusCode, 404)
assert.strictEqual(responseJson.message, 'Channel not found')
})
await t.test('fails with not found channel', async (t) => {
await t.test('fails with not found channel', async () => {
const { accessToken } = await authenticateUserTest()
sinon.stub(prisma, 'channel').value({
findUnique: async () => {
@@ -82,15 +84,15 @@ await tap.test('GET /channels/[channelId]', async (t) => {
}
})
const responseJson = response.json()
t.equal(response.statusCode, 404)
t.equal(responseJson.message, 'Channel not found')
assert.strictEqual(response.statusCode, 404)
assert.strictEqual(responseJson.message, 'Channel not found')
})
await t.test('fails with unauthenticated user', async (t) => {
await t.test('fails with unauthenticated user', async () => {
const response = await application.inject({
method: 'GET',
url: '/channels/1'
})
t.equal(response.statusCode, 401)
assert.strictEqual(response.statusCode, 401)
})
})

View File

@@ -1,20 +1,22 @@
import tap from 'tap'
import test from 'node:test'
import assert from 'node:assert/strict'
import sinon from 'sinon'
import { application } from '../../../../application.js'
import { authenticateUserTest } from '../../../../__test__/utils/authenticateUserTest.js'
import prisma from '../../../../tools/database/prisma.js'
import { channelExample } from '../../../../models/Channel.js'
import { memberExample } from '../../../../models/Member.js'
import { application } from '#src/application.js'
import { authenticateUserTest } from '#src/__test__/utils/authenticateUserTest.js'
import prisma from '#src/tools/database/prisma.js'
import { channelExample } from '#src/models/Channel.js'
import { memberExample } from '#src/models/Member.js'
const newName = 'new channel name'
await tap.test('PUT /channels/[channelId]', async (t) => {
await test('PUT /channels/[channelId]', async (t) => {
t.afterEach(() => {
sinon.restore()
})
await t.test('succeeds', async (t) => {
await t.test('succeeds', async () => {
const defaultChannelId = 5
const { accessToken } = await authenticateUserTest()
sinon.stub(prisma, 'channel').value({
@@ -48,14 +50,14 @@ await tap.test('PUT /channels/[channelId]', async (t) => {
payload: { name: newName }
})
const responseJson = response.json()
t.equal(response.statusCode, 200)
t.equal(responseJson.id, channelExample.id)
t.equal(responseJson.name, newName)
t.equal(responseJson.guildId, channelExample.guildId)
t.equal(responseJson.defaultChannelId, defaultChannelId)
assert.strictEqual(response.statusCode, 200)
assert.strictEqual(responseJson.id, channelExample.id)
assert.strictEqual(responseJson.name, newName)
assert.strictEqual(responseJson.guildId, channelExample.guildId)
assert.strictEqual(responseJson.defaultChannelId, defaultChannelId)
})
await t.test('fails if the channel is not found', async (t) => {
await t.test('fails if the channel is not found', async () => {
const { accessToken } = await authenticateUserTest()
sinon.stub(prisma, 'channel').value({
findUnique: async () => {
@@ -75,10 +77,10 @@ await tap.test('PUT /channels/[channelId]', async (t) => {
},
payload: { name: newName }
})
t.equal(response.statusCode, 404)
assert.strictEqual(response.statusCode, 404)
})
await t.test('fails if the member is not found', async (t) => {
await t.test('fails if the member is not found', async () => {
const { accessToken } = await authenticateUserTest()
sinon.stub(prisma, 'channel').value({
findUnique: async () => {
@@ -98,10 +100,10 @@ await tap.test('PUT /channels/[channelId]', async (t) => {
},
payload: { name: newName }
})
t.equal(response.statusCode, 404)
assert.strictEqual(response.statusCode, 404)
})
await t.test('fails if the member is not owner', async (t) => {
await t.test('fails if the member is not owner', async () => {
const { accessToken } = await authenticateUserTest()
sinon.stub(prisma, 'channel').value({
findUnique: async () => {
@@ -124,6 +126,6 @@ await tap.test('PUT /channels/[channelId]', async (t) => {
},
payload: { name: newName }
})
t.equal(response.statusCode, 400)
assert.strictEqual(response.statusCode, 400)
})
})

View File

@@ -2,10 +2,10 @@ import type { Static } from '@sinclair/typebox'
import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../models/utils.js'
import authenticateUser from '../../../tools/plugins/authenticateUser.js'
import { channelSchema } from '../../../models/Channel.js'
import prisma from '#src/tools/database/prisma.js'
import { fastifyErrors } from '#src/models/utils.js'
import authenticateUser from '#src/tools/plugins/authenticateUser.js'
import { channelSchema } from '#src/models/Channel.js'
const parametersSchema = Type.Object({
channelId: channelSchema.id
@@ -48,8 +48,8 @@ export const deleteChannelService: FastifyPluginAsync = async (fastify) => {
if (request.user == null) {
throw fastify.httpErrors.forbidden()
}
const { user } = request
const { channelId } = request.params
const { user, params } = request
const { channelId } = params
const channelCheck = await prisma.channel.findUnique({
where: { id: channelId }
})

View File

@@ -2,10 +2,10 @@ import type { Static } from '@sinclair/typebox'
import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../models/utils.js'
import authenticateUser from '../../../tools/plugins/authenticateUser.js'
import { channelSchema } from '../../../models/Channel.js'
import prisma from '#src/tools/database/prisma.js'
import { fastifyErrors } from '#src/models/utils.js'
import authenticateUser from '#src/tools/plugins/authenticateUser.js'
import { channelSchema } from '#src/models/Channel.js'
const parametersSchema = Type.Object({
channelId: channelSchema.id

View File

@@ -1,20 +1,22 @@
import tap from 'tap'
import test from 'node:test'
import assert from 'node:assert/strict'
import sinon from 'sinon'
import { application } from '../../../../../application.js'
import { authenticateUserTest } from '../../../../../__test__/utils/authenticateUserTest.js'
import prisma from '../../../../../tools/database/prisma.js'
import { channelExample } from '../../../../../models/Channel.js'
import { memberExample } from '../../../../../models/Member.js'
import { userExample } from '../../../../../models/User.js'
import { messageExample } from '../../../../../models/Message.js'
import { application } from '#src/application.js'
import { authenticateUserTest } from '#src/__test__/utils/authenticateUserTest.js'
import prisma from '#src/tools/database/prisma.js'
import { channelExample } from '#src/models/Channel.js'
import { memberExample } from '#src/models/Member.js'
import { userExample } from '#src/models/User.js'
import { messageExample } from '#src/models/Message.js'
await tap.test('GET /channels/[channelId]/messages', async (t) => {
await test('GET /channels/[channelId]/messages', async (t) => {
t.afterEach(() => {
sinon.restore()
})
await t.test('succeeds', async (t) => {
await t.test('succeeds', async () => {
const { accessToken } = await authenticateUserTest()
sinon.stub(prisma, 'channel').value({
findUnique: async () => {
@@ -42,19 +44,19 @@ await tap.test('GET /channels/[channelId]/messages', async (t) => {
}
})
const responseJson = response.json()
t.equal(response.statusCode, 200)
t.equal(responseJson.length, 1)
t.equal(responseJson[0].id, messageExample.id)
t.equal(responseJson[0].value, messageExample.value)
t.equal(responseJson[0].type, messageExample.type)
t.equal(responseJson[0].mimetype, messageExample.mimetype)
t.equal(responseJson[0].member.id, memberExample.id)
t.equal(responseJson[0].member.isOwner, memberExample.isOwner)
t.equal(responseJson[0].member.user.id, userExample.id)
t.equal(responseJson[0].member.user.name, userExample.name)
assert.strictEqual(response.statusCode, 200)
assert.strictEqual(responseJson.length, 1)
assert.strictEqual(responseJson[0].id, messageExample.id)
assert.strictEqual(responseJson[0].value, messageExample.value)
assert.strictEqual(responseJson[0].type, messageExample.type)
assert.strictEqual(responseJson[0].mimetype, messageExample.mimetype)
assert.strictEqual(responseJson[0].member.id, memberExample.id)
assert.strictEqual(responseJson[0].member.isOwner, memberExample.isOwner)
assert.strictEqual(responseJson[0].member.user.id, userExample.id)
assert.strictEqual(responseJson[0].member.user.name, userExample.name)
})
await t.test('fails with not found channel', async (t) => {
await t.test('fails with not found channel', async () => {
const { accessToken } = await authenticateUserTest()
sinon.stub(prisma, 'channel').value({
findUnique: async () => {
@@ -77,11 +79,11 @@ await tap.test('GET /channels/[channelId]/messages', async (t) => {
}
})
const responseJson = response.json()
t.equal(response.statusCode, 404)
t.equal(responseJson.message, 'Channel not found')
assert.strictEqual(response.statusCode, 404)
assert.strictEqual(responseJson.message, 'Channel not found')
})
await t.test('fails with not found member', async (t) => {
await t.test('fails with not found member', async () => {
const { accessToken } = await authenticateUserTest()
sinon.stub(prisma, 'channel').value({
findUnique: async () => {
@@ -101,15 +103,15 @@ await tap.test('GET /channels/[channelId]/messages', async (t) => {
}
})
const responseJson = response.json()
t.equal(response.statusCode, 404)
t.equal(responseJson.message, 'Channel not found')
assert.strictEqual(response.statusCode, 404)
assert.strictEqual(responseJson.message, 'Channel not found')
})
await t.test('fails with unauthenticated user', async (t) => {
await t.test('fails with unauthenticated user', async () => {
const response = await application.inject({
method: 'GET',
url: `/channels/1/messages`
})
t.equal(response.statusCode, 401)
assert.strictEqual(response.statusCode, 401)
})
})

View File

@@ -1,20 +1,22 @@
import tap from 'tap'
import test from 'node:test'
import assert from 'node:assert/strict'
import sinon from 'sinon'
import { application } from '../../../../../application.js'
import { authenticateUserTest } from '../../../../../__test__/utils/authenticateUserTest.js'
import prisma from '../../../../../tools/database/prisma.js'
import { channelExample } from '../../../../../models/Channel.js'
import { memberExample } from '../../../../../models/Member.js'
import { userExample } from '../../../../../models/User.js'
import { messageExample } from '../../../../../models/Message.js'
import { application } from '#src/application.js'
import { authenticateUserTest } from '#src/__test__/utils/authenticateUserTest.js'
import prisma from '#src/tools/database/prisma.js'
import { channelExample } from '#src/models/Channel.js'
import { memberExample } from '#src/models/Member.js'
import { userExample } from '#src/models/User.js'
import { messageExample } from '#src/models/Message.js'
await tap.test('POST /channels/[channelId]/messages', async (t) => {
await test('POST /channels/[channelId]/messages', async (t) => {
t.afterEach(() => {
sinon.restore()
})
await t.test('succeeds', async (t) => {
await t.test('succeeds', async () => {
const { accessToken } = await authenticateUserTest()
sinon.stub(prisma, 'channel').value({
findUnique: async () => {
@@ -43,18 +45,18 @@ await tap.test('POST /channels/[channelId]/messages', async (t) => {
payload: { value: messageExample.value }
})
const responseJson = response.json()
t.equal(response.statusCode, 201)
t.equal(responseJson.id, messageExample.id)
t.equal(responseJson.value, messageExample.value)
t.equal(responseJson.type, messageExample.type)
t.equal(responseJson.mimetype, messageExample.mimetype)
t.equal(responseJson.member.id, memberExample.id)
t.equal(responseJson.member.isOwner, memberExample.isOwner)
t.equal(responseJson.member.user.id, userExample.id)
t.equal(responseJson.member.user.name, userExample.name)
assert.strictEqual(response.statusCode, 201)
assert.strictEqual(responseJson.id, messageExample.id)
assert.strictEqual(responseJson.value, messageExample.value)
assert.strictEqual(responseJson.type, messageExample.type)
assert.strictEqual(responseJson.mimetype, messageExample.mimetype)
assert.strictEqual(responseJson.member.id, memberExample.id)
assert.strictEqual(responseJson.member.isOwner, memberExample.isOwner)
assert.strictEqual(responseJson.member.user.id, userExample.id)
assert.strictEqual(responseJson.member.user.name, userExample.name)
})
await t.test('fails with no message value', async (t) => {
await t.test('fails with no message value', async () => {
const { accessToken } = await authenticateUserTest()
sinon.stub(prisma, 'channel').value({
findUnique: async () => {
@@ -77,10 +79,10 @@ await tap.test('POST /channels/[channelId]/messages', async (t) => {
},
payload: {}
})
t.equal(response.statusCode, 400)
assert.strictEqual(response.statusCode, 400)
})
await t.test('fails with not found channel', async (t) => {
await t.test('fails with not found channel', async () => {
const { accessToken } = await authenticateUserTest()
sinon.stub(prisma, 'channel').value({
findUnique: async () => {
@@ -104,11 +106,11 @@ await tap.test('POST /channels/[channelId]/messages', async (t) => {
payload: { value: messageExample.value }
})
const responseJson = response.json()
t.equal(response.statusCode, 404)
t.equal(responseJson.message, 'Channel not found')
assert.strictEqual(response.statusCode, 404)
assert.strictEqual(responseJson.message, 'Channel not found')
})
await t.test('fails with not found member', async (t) => {
await t.test('fails with not found member', async () => {
const { accessToken } = await authenticateUserTest()
sinon.stub(prisma, 'channel').value({
findUnique: async () => {
@@ -129,7 +131,7 @@ await tap.test('POST /channels/[channelId]/messages', async (t) => {
payload: { value: messageExample.value }
})
const responseJson = response.json()
t.equal(response.statusCode, 404)
t.equal(responseJson.message, 'Channel not found')
assert.strictEqual(response.statusCode, 404)
assert.strictEqual(responseJson.message, 'Channel not found')
})
})

View File

@@ -2,17 +2,17 @@ import type { Static } from '@sinclair/typebox'
import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../../models/utils.js'
import authenticateUser from '../../../../tools/plugins/authenticateUser.js'
import { messageSchema } from '../../../../models/Message.js'
import { memberSchema } from '../../../../models/Member.js'
import { userPublicWithoutSettingsSchema } from '../../../../models/User.js'
import prisma from '#src/tools/database/prisma.js'
import { fastifyErrors } from '#src/models/utils.js'
import authenticateUser from '#src/tools/plugins/authenticateUser.js'
import { messageSchema } from '#src/models/Message.js'
import { memberSchema } from '#src/models/Member.js'
import { userPublicWithoutSettingsSchema } from '#src/models/User.js'
import {
getPaginationOptions,
queryPaginationObjectSchema
} from '../../../../tools/database/pagination.js'
import { channelSchema } from '../../../../models/Channel.js'
} from '#src/tools/database/pagination.js'
import { channelSchema } from '#src/models/Channel.js'
type QuerySchemaType = Static<typeof queryPaginationObjectSchema>

View File

@@ -2,13 +2,13 @@ import type { Static } from '@sinclair/typebox'
import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../../models/utils.js'
import authenticateUser from '../../../../tools/plugins/authenticateUser.js'
import { messageSchema } from '../../../../models/Message.js'
import { channelSchema } from '../../../../models/Channel.js'
import { memberSchema } from '../../../../models/Member.js'
import { userPublicWithoutSettingsSchema } from '../../../../models/User.js'
import prisma from '#src/tools/database/prisma.js'
import { fastifyErrors } from '#src/models/utils.js'
import authenticateUser from '#src/tools/plugins/authenticateUser.js'
import { messageSchema } from '#src/models/Message.js'
import { channelSchema } from '#src/models/Channel.js'
import { memberSchema } from '#src/models/Member.js'
import { userPublicWithoutSettingsSchema } from '#src/models/User.js'
const parametersSchema = Type.Object({
channelId: channelSchema.id

View File

@@ -3,14 +3,14 @@ import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import fastifyMultipart from '@fastify/multipart'
import prisma from '../../../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../../../models/utils.js'
import authenticateUser from '../../../../../tools/plugins/authenticateUser.js'
import { messageSchema } from '../../../../../models/Message.js'
import { memberSchema } from '../../../../../models/Member.js'
import { userPublicWithoutSettingsSchema } from '../../../../../models/User.js'
import { channelSchema } from '../../../../../models/Channel.js'
import { uploadFile } from '../../../../../tools/utils/uploadFile.js'
import prisma from '#src/tools/database/prisma.js'
import { fastifyErrors } from '#src/models/utils.js'
import authenticateUser from '#src/tools/plugins/authenticateUser.js'
import { messageSchema } from '#src/models/Message.js'
import { memberSchema } from '#src/models/Member.js'
import { userPublicWithoutSettingsSchema } from '#src/models/User.js'
import { channelSchema } from '#src/models/Channel.js'
import { uploadFile } from '#src/tools/utils/uploadFile.js'
const parametersSchema = Type.Object({
channelId: channelSchema.id

View File

@@ -2,10 +2,10 @@ import type { Static } from '@sinclair/typebox'
import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../models/utils.js'
import authenticateUser from '../../../tools/plugins/authenticateUser.js'
import { channelSchema } from '../../../models/Channel.js'
import prisma from '#src/tools/database/prisma.js'
import { fastifyErrors } from '#src/models/utils.js'
import authenticateUser from '#src/tools/plugins/authenticateUser.js'
import { channelSchema } from '#src/models/Channel.js'
const bodyPutServiceSchema = Type.Object({
name: channelSchema.name
@@ -56,9 +56,9 @@ export const putChannelService: FastifyPluginAsync = async (fastify) => {
if (request.user == null) {
throw fastify.httpErrors.forbidden()
}
const { user } = request
const { channelId } = request.params
const { name } = request.body
const { user, params, body } = request
const { channelId } = params
const { name } = body
const channelCheck = await prisma.channel.findUnique({
where: { id: channelId }
})