fix: update dependencies to latest
This commit is contained in:
@ -1,17 +1,19 @@
|
||||
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 prisma from '../../../../tools/database/prisma.js'
|
||||
import { userExample } from '../../../../models/User.js'
|
||||
import { userSettingsExample } from '../../../../models/UserSettings.js'
|
||||
import { application } from '#src/application.js'
|
||||
import prisma from '#src/tools/database/prisma.js'
|
||||
import { userExample } from '#src/models/User.js'
|
||||
import { userSettingsExample } from '#src/models/UserSettings.js'
|
||||
|
||||
await tap.test('GET /users/[userId]', async (t) => {
|
||||
await test('GET /users/[userId]', async (t) => {
|
||||
t.afterEach(() => {
|
||||
sinon.restore()
|
||||
})
|
||||
|
||||
await t.test('succeeds', async (t) => {
|
||||
await t.test('succeeds', async () => {
|
||||
sinon.stub(prisma, 'guild').value({
|
||||
findMany: async () => {
|
||||
return []
|
||||
@ -32,12 +34,12 @@ await tap.test('GET /users/[userId]', async (t) => {
|
||||
url: `/users/${userExample.id}`
|
||||
})
|
||||
const responseJson = response.json()
|
||||
t.equal(response.statusCode, 200)
|
||||
t.equal(responseJson.user.id, userExample.id)
|
||||
t.equal(responseJson.user.name, userExample.name)
|
||||
assert.strictEqual(response.statusCode, 200)
|
||||
assert.strictEqual(responseJson.user.id, userExample.id)
|
||||
assert.strictEqual(responseJson.user.name, userExample.name)
|
||||
})
|
||||
|
||||
await t.test('fails with not found user', async (t) => {
|
||||
await t.test('fails with not found user', async () => {
|
||||
sinon.stub(prisma, 'userSetting').value({
|
||||
findFirst: async () => {
|
||||
return null
|
||||
@ -48,7 +50,7 @@ await tap.test('GET /users/[userId]', async (t) => {
|
||||
url: `/users/1`
|
||||
})
|
||||
const responseJson = response.json()
|
||||
t.equal(response.statusCode, 404)
|
||||
t.equal(responseJson.message, 'User not found')
|
||||
assert.strictEqual(response.statusCode, 404)
|
||||
assert.strictEqual(responseJson.message, 'User not found')
|
||||
})
|
||||
})
|
||||
|
@ -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 { userPublicSchema } from '../../../models/User.js'
|
||||
import { guildSchema } from '../../../models/Guild.js'
|
||||
import prisma from '#src/tools/database/prisma.js'
|
||||
import { fastifyErrors } from '#src/models/utils.js'
|
||||
import { userPublicSchema } from '#src/models/User.js'
|
||||
import { guildSchema } from '#src/models/Guild.js'
|
||||
|
||||
const parametersGetUserSchema = Type.Object({
|
||||
userId: userPublicSchema.id
|
||||
|
@ -1,16 +1,18 @@
|
||||
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 prisma from '../../../../tools/database/prisma.js'
|
||||
import { userExample } from '../../../../models/User.js'
|
||||
import { application } from '#src/application.js'
|
||||
import prisma from '#src/tools/database/prisma.js'
|
||||
import { userExample } from '#src/models/User.js'
|
||||
|
||||
await tap.test('GET /users/confirm-email', async (t) => {
|
||||
await test('GET /users/confirm-email', async (t) => {
|
||||
t.afterEach(() => {
|
||||
sinon.restore()
|
||||
})
|
||||
|
||||
await t.test('succeeds', async (t) => {
|
||||
await t.test('succeeds', async () => {
|
||||
sinon.stub(prisma, 'user').value({
|
||||
findFirst: async () => {
|
||||
return userExample
|
||||
@ -26,10 +28,10 @@ await tap.test('GET /users/confirm-email', async (t) => {
|
||||
temporaryToken: userExample.temporaryToken ?? ''
|
||||
}
|
||||
})
|
||||
t.equal(response.statusCode, 200)
|
||||
assert.strictEqual(response.statusCode, 200)
|
||||
})
|
||||
|
||||
await t.test('should fails with invalid `temporaryToken`', async (t) => {
|
||||
await t.test('should fails with invalid `temporaryToken`', async () => {
|
||||
sinon.stub(prisma, 'user').value({
|
||||
findFirst: async () => {
|
||||
return null
|
||||
@ -45,6 +47,6 @@ await tap.test('GET /users/confirm-email', async (t) => {
|
||||
temporaryToken: userExample.temporaryToken ?? ''
|
||||
}
|
||||
})
|
||||
t.equal(response.statusCode, 403)
|
||||
assert.strictEqual(response.statusCode, 403)
|
||||
})
|
||||
})
|
||||
|
@ -2,9 +2,9 @@ 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 { userSchema } from '../../../models/User.js'
|
||||
import prisma from '#src/tools/database/prisma.js'
|
||||
import { fastifyErrors } from '#src/models/utils.js'
|
||||
import { userSchema } from '#src/models/User.js'
|
||||
|
||||
const queryGetConfirmEmailSchema = Type.Object({
|
||||
redirectURI: Type.Optional(Type.String({ format: 'uri-reference' })),
|
||||
|
@ -1,15 +1,17 @@
|
||||
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 { application } from '#src/application.js'
|
||||
import { authenticateUserTest } from '#src/__test__/utils/authenticateUserTest.js'
|
||||
|
||||
await tap.test('GET /users/current', async (t) => {
|
||||
await test('GET /users/current', async (t) => {
|
||||
t.afterEach(() => {
|
||||
sinon.restore()
|
||||
})
|
||||
|
||||
await t.test('succeeds', async (t) => {
|
||||
await t.test('succeeds', async () => {
|
||||
const { accessToken, user } = await authenticateUserTest()
|
||||
const response = await application.inject({
|
||||
method: 'GET',
|
||||
@ -19,16 +21,16 @@ await tap.test('GET /users/current', async (t) => {
|
||||
}
|
||||
})
|
||||
const responseJson = response.json()
|
||||
t.equal(response.statusCode, 200)
|
||||
t.equal(responseJson.user.name, user.name)
|
||||
t.strictSame(responseJson.user.strategies, ['Local'])
|
||||
assert.strictEqual(response.statusCode, 200)
|
||||
assert.strictEqual(responseJson.user.name, user.name)
|
||||
assert.deepStrictEqual(responseJson.user.strategies, ['Local'])
|
||||
})
|
||||
|
||||
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: '/users/current'
|
||||
})
|
||||
t.equal(response.statusCode, 401)
|
||||
assert.strictEqual(response.statusCode, 401)
|
||||
})
|
||||
})
|
||||
|
@ -1,16 +1,18 @@
|
||||
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 prisma from '../../../../tools/database/prisma.js'
|
||||
import { authenticateUserTest } from '../../../../__test__/utils/authenticateUserTest.js'
|
||||
import { application } from '#src/application.js'
|
||||
import prisma from '#src/tools/database/prisma.js'
|
||||
import { authenticateUserTest } from '#src/__test__/utils/authenticateUserTest.js'
|
||||
|
||||
await tap.test('PUT /users/current', async (t) => {
|
||||
await test('PUT /users/current', async (t) => {
|
||||
t.afterEach(() => {
|
||||
sinon.restore()
|
||||
})
|
||||
|
||||
await t.test('succeeds with valid accessToken and valid name', async (t) => {
|
||||
await t.test('succeeds with valid accessToken and valid name', async () => {
|
||||
const newName = 'John Doe'
|
||||
const { accessToken, user, userStubValue } = await authenticateUserTest()
|
||||
sinon.stub(prisma, 'user').value({
|
||||
@ -36,11 +38,11 @@ await tap.test('PUT /users/current', async (t) => {
|
||||
}
|
||||
})
|
||||
const responseJson = response.json()
|
||||
t.equal(response.statusCode, 200)
|
||||
t.equal(responseJson.user.name, newName)
|
||||
assert.strictEqual(response.statusCode, 200)
|
||||
assert.strictEqual(responseJson.user.name, newName)
|
||||
})
|
||||
|
||||
await t.test('succeeds and only update the status', async (t) => {
|
||||
await t.test('succeeds and only update the status', async () => {
|
||||
const newStatus = '👀 Working on secret projects...'
|
||||
const { accessToken, user, userStubValue } = await authenticateUserTest()
|
||||
sinon.stub(prisma, 'user').value({
|
||||
@ -66,12 +68,12 @@ await tap.test('PUT /users/current', async (t) => {
|
||||
}
|
||||
})
|
||||
const responseJson = response.json()
|
||||
t.equal(response.statusCode, 200)
|
||||
t.equal(responseJson.user.name, user.name)
|
||||
t.equal(responseJson.user.status, newStatus)
|
||||
assert.strictEqual(response.statusCode, 200)
|
||||
assert.strictEqual(responseJson.user.name, user.name)
|
||||
assert.strictEqual(responseJson.user.status, newStatus)
|
||||
})
|
||||
|
||||
await t.test('fails with name already used', async (t) => {
|
||||
await t.test('fails with name already used', async () => {
|
||||
const newName = 'John Doe'
|
||||
const { accessToken, user, userStubValue } = await authenticateUserTest()
|
||||
sinon.stub(prisma, 'user').value({
|
||||
@ -90,10 +92,10 @@ await tap.test('PUT /users/current', async (t) => {
|
||||
name: newName
|
||||
}
|
||||
})
|
||||
t.equal(response.statusCode, 400)
|
||||
assert.strictEqual(response.statusCode, 400)
|
||||
})
|
||||
|
||||
await t.test('fails with invalid website url', async (t) => {
|
||||
await t.test('fails with invalid website url', async () => {
|
||||
const newWebsite = 'invalid website url'
|
||||
const { accessToken } = await authenticateUserTest()
|
||||
const response = await application.inject({
|
||||
@ -106,10 +108,10 @@ await tap.test('PUT /users/current', async (t) => {
|
||||
website: newWebsite
|
||||
}
|
||||
})
|
||||
t.equal(response.statusCode, 400)
|
||||
assert.strictEqual(response.statusCode, 400)
|
||||
})
|
||||
|
||||
await t.test('succeeds with valid website url', async (t) => {
|
||||
await t.test('succeeds with valid website url', async () => {
|
||||
const newWebsite = 'https://somerandomwebsite.com'
|
||||
const { accessToken, user, userStubValue } = await authenticateUserTest()
|
||||
sinon.stub(prisma, 'user').value({
|
||||
@ -135,8 +137,8 @@ await tap.test('PUT /users/current', async (t) => {
|
||||
}
|
||||
})
|
||||
const responseJson = response.json()
|
||||
t.equal(response.statusCode, 200)
|
||||
t.equal(responseJson.user.name, user.name)
|
||||
t.equal(responseJson.user.website, newWebsite)
|
||||
assert.strictEqual(response.statusCode, 200)
|
||||
assert.strictEqual(responseJson.user.name, user.name)
|
||||
assert.strictEqual(responseJson.user.website, newWebsite)
|
||||
})
|
||||
})
|
||||
|
@ -1,9 +1,9 @@
|
||||
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 { userCurrentSchema } 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 { userCurrentSchema } from '#src/models/User.js'
|
||||
|
||||
const getCurrentUserSchema: FastifySchema = {
|
||||
description: 'GET the current connected user',
|
||||
|
@ -2,10 +2,10 @@ import { Type } from '@sinclair/typebox'
|
||||
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
|
||||
import fastifyMultipart from '@fastify/multipart'
|
||||
|
||||
import authenticateUser from '../../../../tools/plugins/authenticateUser.js'
|
||||
import { fastifyErrors } from '../../../../models/utils.js'
|
||||
import prisma from '../../../../tools/database/prisma.js'
|
||||
import { uploadFile } from '../../../../tools/utils/uploadFile.js'
|
||||
import authenticateUser from '#src/tools/plugins/authenticateUser.js'
|
||||
import { fastifyErrors } from '#src/models/utils.js'
|
||||
import prisma from '#src/tools/database/prisma.js'
|
||||
import { uploadFile } from '#src/tools/utils/uploadFile.js'
|
||||
|
||||
const putServiceSchema: FastifySchema = {
|
||||
description: 'Edit the current connected user logo',
|
||||
|
@ -4,14 +4,14 @@ 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 { userCurrentSchema, userSchema } from '../../../models/User.js'
|
||||
import { sendEmail } from '../../../tools/email/sendEmail.js'
|
||||
import { API_URL } from '../../../tools/configurations.js'
|
||||
import type { Language, Theme } from '../../../models/UserSettings.js'
|
||||
import { parseStringNullish } from '../../../tools/utils/parseStringNullish.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 { userCurrentSchema, userSchema } from '#src/models/User.js'
|
||||
import { sendEmail } from '#src/tools/email/sendEmail.js'
|
||||
import { API_URL } from '#src/tools/configurations.js'
|
||||
import type { Language, Theme } from '#src/models/UserSettings.js'
|
||||
import { parseStringNullish } from '#src/tools/utils/parseStringNullish.js'
|
||||
|
||||
const bodyPutServiceSchema = Type.Object({
|
||||
name: Type.Optional(userSchema.name),
|
||||
|
@ -1,19 +1,21 @@
|
||||
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 { userSettingsExample } from '../../../../../models/UserSettings.js'
|
||||
import { application } from '#src/application.js'
|
||||
import { authenticateUserTest } from '#src/__test__/utils/authenticateUserTest.js'
|
||||
import prisma from '#src/tools/database/prisma.js'
|
||||
import { userSettingsExample } from '#src/models/UserSettings.js'
|
||||
|
||||
await tap.test('PUT /users/current/settings', async (t) => {
|
||||
await test('PUT /users/current/settings', async (t) => {
|
||||
t.afterEach(() => {
|
||||
sinon.restore()
|
||||
})
|
||||
|
||||
await t.test(
|
||||
'succeeds and edit the theme, language, isPublicEmail and isPublicGuilds',
|
||||
async (t) => {
|
||||
async () => {
|
||||
const newSettings = {
|
||||
theme: 'light',
|
||||
language: 'fr',
|
||||
@ -42,15 +44,21 @@ await tap.test('PUT /users/current/settings', async (t) => {
|
||||
payload: newSettings
|
||||
})
|
||||
const responseJson = response.json()
|
||||
t.equal(response.statusCode, 200)
|
||||
t.equal(responseJson.settings.theme, newSettings.theme)
|
||||
t.equal(responseJson.settings.language, newSettings.language)
|
||||
t.equal(responseJson.settings.isPublicEmail, newSettings.isPublicEmail)
|
||||
t.equal(responseJson.settings.isPublicGuilds, newSettings.isPublicGuilds)
|
||||
assert.strictEqual(response.statusCode, 200)
|
||||
assert.strictEqual(responseJson.settings.theme, newSettings.theme)
|
||||
assert.strictEqual(responseJson.settings.language, newSettings.language)
|
||||
assert.strictEqual(
|
||||
responseJson.settings.isPublicEmail,
|
||||
newSettings.isPublicEmail
|
||||
)
|
||||
assert.strictEqual(
|
||||
responseJson.settings.isPublicGuilds,
|
||||
newSettings.isPublicGuilds
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
await t.test('fails with invalid language', async (t) => {
|
||||
await t.test('fails with invalid language', async () => {
|
||||
const newSettings = {
|
||||
language: 'somerandomlanguage'
|
||||
}
|
||||
@ -75,6 +83,6 @@ await tap.test('PUT /users/current/settings', async (t) => {
|
||||
},
|
||||
payload: newSettings
|
||||
})
|
||||
t.equal(response.statusCode, 400)
|
||||
assert.strictEqual(response.statusCode, 400)
|
||||
})
|
||||
})
|
||||
|
@ -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 { userSettingsSchema } from '../../../../models/UserSettings.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 { userSettingsSchema } from '#src/models/UserSettings.js'
|
||||
|
||||
const bodyPutServiceSchema = Type.Object({
|
||||
theme: Type.Optional(userSettingsSchema.theme),
|
||||
|
@ -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 { oauthSchema } from '../../../../models/OAuth.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 { oauthSchema } from '#src/models/OAuth.js'
|
||||
|
||||
const parametersSchema = Type.Object({
|
||||
provider: oauthSchema.provider
|
||||
@ -45,8 +45,8 @@ export const deleteProviderService: FastifyPluginAsync = async (fastify) => {
|
||||
if (request.user == null) {
|
||||
throw fastify.httpErrors.forbidden()
|
||||
}
|
||||
const { user } = request
|
||||
const { provider } = request.params
|
||||
const { user, params } = request
|
||||
const { provider } = params
|
||||
const OAuths = await prisma.oAuth.findMany({
|
||||
where: { userId: user.current.id }
|
||||
})
|
||||
|
@ -2,7 +2,7 @@ import querystring from 'node:querystring'
|
||||
|
||||
import axios from 'axios'
|
||||
|
||||
import { OAuthStrategy } from '../../../../../tools/utils/OAuthStrategy.js'
|
||||
import { OAuthStrategy } from '#src/tools/utils/OAuthStrategy.js'
|
||||
|
||||
export const DISCORD_PROVIDER = 'Discord'
|
||||
export const DISCORD_BASE_URL = 'https://discord.com/api/v10'
|
||||
|
@ -2,10 +2,10 @@ import type { Static } from '@sinclair/typebox'
|
||||
import { Type } from '@sinclair/typebox'
|
||||
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
|
||||
|
||||
import { API_URL } from '../../../../../tools/configurations.js'
|
||||
import { fastifyErrors } from '../../../../../models/utils.js'
|
||||
import { API_URL } from '#src/tools/configurations.js'
|
||||
import { fastifyErrors } from '#src/models/utils.js'
|
||||
import { DISCORD_BASE_URL, DISCORD_CLIENT_ID } from '../__utils__/utils.js'
|
||||
import authenticateUser from '../../../../../tools/plugins/authenticateUser.js'
|
||||
import authenticateUser from '#src/tools/plugins/authenticateUser.js'
|
||||
|
||||
const querySchema = Type.Object({
|
||||
redirectURI: Type.String({ format: 'uri-reference' })
|
||||
|
@ -2,11 +2,11 @@ import type { Static } from '@sinclair/typebox'
|
||||
import { Type } from '@sinclair/typebox'
|
||||
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
|
||||
|
||||
import { API_URL } from '../../../../../tools/configurations.js'
|
||||
import { fastifyErrors } from '../../../../../models/utils.js'
|
||||
import { API_URL } from '#src/tools/configurations.js'
|
||||
import { fastifyErrors } from '#src/models/utils.js'
|
||||
import { discordStrategy, getDiscordUserData } from '../__utils__/utils.js'
|
||||
import { buildQueryURL } from '../../../../../tools/utils/buildQueryURL.js'
|
||||
import { getUserWithBearerToken } from '../../../../../tools/plugins/authenticateUser.js'
|
||||
import { buildQueryURL } from '#src/tools/utils/buildQueryURL.js'
|
||||
import { getUserWithBearerToken } from '#src/tools/plugins/authenticateUser.js'
|
||||
|
||||
const querySchema = Type.Object({
|
||||
code: Type.String(),
|
||||
|
@ -2,10 +2,10 @@ import type { Static } from '@sinclair/typebox'
|
||||
import { Type } from '@sinclair/typebox'
|
||||
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
|
||||
|
||||
import { API_URL } from '../../../../../tools/configurations.js'
|
||||
import { fastifyErrors } from '../../../../../models/utils.js'
|
||||
import { API_URL } from '#src/tools/configurations.js'
|
||||
import { fastifyErrors } from '#src/models/utils.js'
|
||||
import { discordStrategy, getDiscordUserData } from '../__utils__/utils.js'
|
||||
import { buildQueryURL } from '../../../../../tools/utils/buildQueryURL.js'
|
||||
import { buildQueryURL } from '#src/tools/utils/buildQueryURL.js'
|
||||
|
||||
const querySchema = Type.Object({
|
||||
code: Type.String(),
|
||||
|
@ -2,8 +2,8 @@ import type { Static } from '@sinclair/typebox'
|
||||
import { Type } from '@sinclair/typebox'
|
||||
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
|
||||
|
||||
import { API_URL } from '../../../../../tools/configurations.js'
|
||||
import { fastifyErrors } from '../../../../../models/utils.js'
|
||||
import { API_URL } from '#src/tools/configurations.js'
|
||||
import { fastifyErrors } from '#src/models/utils.js'
|
||||
import { DISCORD_BASE_URL, DISCORD_CLIENT_ID } from '../__utils__/utils.js'
|
||||
|
||||
const querySchema = Type.Object({
|
||||
|
@ -2,7 +2,7 @@ import querystring from 'node:querystring'
|
||||
|
||||
import axios from 'axios'
|
||||
|
||||
import { OAuthStrategy } from '../../../../../tools/utils/OAuthStrategy.js'
|
||||
import { OAuthStrategy } from '#src/tools/utils/OAuthStrategy.js'
|
||||
|
||||
export const GITHUB_PROVIDER = 'GitHub'
|
||||
export const GITHUB_BASE_URL = 'https://github.com'
|
||||
|
@ -2,10 +2,10 @@ import type { Static } from '@sinclair/typebox'
|
||||
import { Type } from '@sinclair/typebox'
|
||||
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
|
||||
|
||||
import { API_URL } from '../../../../../tools/configurations.js'
|
||||
import { fastifyErrors } from '../../../../../models/utils.js'
|
||||
import { API_URL } from '#src/tools/configurations.js'
|
||||
import { fastifyErrors } from '#src/models/utils.js'
|
||||
import { GITHUB_BASE_URL, GITHUB_CLIENT_ID } from '../__utils__/utils.js'
|
||||
import authenticateUser from '../../../../../tools/plugins/authenticateUser.js'
|
||||
import authenticateUser from '#src/tools/plugins/authenticateUser.js'
|
||||
|
||||
const querySchema = Type.Object({
|
||||
redirectURI: Type.String({ format: 'uri-reference' })
|
||||
|
@ -2,11 +2,11 @@ import type { Static } from '@sinclair/typebox'
|
||||
import { Type } from '@sinclair/typebox'
|
||||
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
|
||||
|
||||
import { API_URL } from '../../../../../tools/configurations.js'
|
||||
import { fastifyErrors } from '../../../../../models/utils.js'
|
||||
import { API_URL } from '#src/tools/configurations.js'
|
||||
import { fastifyErrors } from '#src/models/utils.js'
|
||||
import { githubStrategy, getGitHubUserData } from '../__utils__/utils.js'
|
||||
import { buildQueryURL } from '../../../../../tools/utils/buildQueryURL.js'
|
||||
import { getUserWithBearerToken } from '../../../../../tools/plugins/authenticateUser.js'
|
||||
import { buildQueryURL } from '#src/tools/utils/buildQueryURL.js'
|
||||
import { getUserWithBearerToken } from '#src/tools/plugins/authenticateUser.js'
|
||||
|
||||
const querySchema = Type.Object({
|
||||
code: Type.String(),
|
||||
|
@ -2,10 +2,10 @@ import type { Static } from '@sinclair/typebox'
|
||||
import { Type } from '@sinclair/typebox'
|
||||
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
|
||||
|
||||
import { API_URL } from '../../../../../tools/configurations.js'
|
||||
import { fastifyErrors } from '../../../../../models/utils.js'
|
||||
import { API_URL } from '#src/tools/configurations.js'
|
||||
import { fastifyErrors } from '#src/models/utils.js'
|
||||
import { githubStrategy, getGitHubUserData } from '../__utils__/utils.js'
|
||||
import { buildQueryURL } from '../../../../../tools/utils/buildQueryURL.js'
|
||||
import { buildQueryURL } from '#src/tools/utils/buildQueryURL.js'
|
||||
|
||||
const querySchema = Type.Object({
|
||||
code: Type.String(),
|
||||
|
@ -2,8 +2,8 @@ import type { Static } from '@sinclair/typebox'
|
||||
import { Type } from '@sinclair/typebox'
|
||||
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
|
||||
|
||||
import { API_URL } from '../../../../../tools/configurations.js'
|
||||
import { fastifyErrors } from '../../../../../models/utils.js'
|
||||
import { API_URL } from '#src/tools/configurations.js'
|
||||
import { fastifyErrors } from '#src/models/utils.js'
|
||||
import { GITHUB_BASE_URL, GITHUB_CLIENT_ID } from '../__utils__/utils.js'
|
||||
|
||||
const querySchema = Type.Object({
|
||||
|
@ -2,7 +2,7 @@ import querystring from 'node:querystring'
|
||||
|
||||
import axios from 'axios'
|
||||
|
||||
import { OAuthStrategy } from '../../../../../tools/utils/OAuthStrategy.js'
|
||||
import { OAuthStrategy } from '#src/tools/utils/OAuthStrategy.js'
|
||||
|
||||
export const GOOGLE_PROVIDER = 'Google'
|
||||
export const GOOGLE_BASE_URL = 'https://accounts.google.com/o/oauth2/v2/auth'
|
||||
|
@ -2,10 +2,10 @@ import type { Static } from '@sinclair/typebox'
|
||||
import { Type } from '@sinclair/typebox'
|
||||
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
|
||||
|
||||
import { API_URL } from '../../../../../tools/configurations.js'
|
||||
import { fastifyErrors } from '../../../../../models/utils.js'
|
||||
import { API_URL } from '#src/tools/configurations.js'
|
||||
import { fastifyErrors } from '#src/models/utils.js'
|
||||
import { GOOGLE_BASE_URL, GOOGLE_CLIENT_ID } from '../__utils__/utils.js'
|
||||
import authenticateUser from '../../../../../tools/plugins/authenticateUser.js'
|
||||
import authenticateUser from '#src/tools/plugins/authenticateUser.js'
|
||||
|
||||
const querySchema = Type.Object({
|
||||
redirectURI: Type.String({ format: 'uri-reference' })
|
||||
|
@ -2,11 +2,11 @@ import type { Static } from '@sinclair/typebox'
|
||||
import { Type } from '@sinclair/typebox'
|
||||
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
|
||||
|
||||
import { API_URL } from '../../../../../tools/configurations.js'
|
||||
import { fastifyErrors } from '../../../../../models/utils.js'
|
||||
import { API_URL } from '#src/tools/configurations.js'
|
||||
import { fastifyErrors } from '#src/models/utils.js'
|
||||
import { googleStrategy, getGoogleUserData } from '../__utils__/utils.js'
|
||||
import { buildQueryURL } from '../../../../../tools/utils/buildQueryURL.js'
|
||||
import { getUserWithBearerToken } from '../../../../../tools/plugins/authenticateUser.js'
|
||||
import { buildQueryURL } from '#src/tools/utils/buildQueryURL.js'
|
||||
import { getUserWithBearerToken } from '#src/tools/plugins/authenticateUser.js'
|
||||
|
||||
const querySchema = Type.Object({
|
||||
code: Type.String(),
|
||||
|
@ -2,10 +2,10 @@ import type { Static } from '@sinclair/typebox'
|
||||
import { Type } from '@sinclair/typebox'
|
||||
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
|
||||
|
||||
import { API_URL } from '../../../../../tools/configurations.js'
|
||||
import { fastifyErrors } from '../../../../../models/utils.js'
|
||||
import { API_URL } from '#src/tools/configurations.js'
|
||||
import { fastifyErrors } from '#src/models/utils.js'
|
||||
import { googleStrategy, getGoogleUserData } from '../__utils__/utils.js'
|
||||
import { buildQueryURL } from '../../../../../tools/utils/buildQueryURL.js'
|
||||
import { buildQueryURL } from '#src/tools/utils/buildQueryURL.js'
|
||||
|
||||
const querySchema = Type.Object({
|
||||
code: Type.String(),
|
||||
|
@ -2,8 +2,8 @@ import type { Static } from '@sinclair/typebox'
|
||||
import { Type } from '@sinclair/typebox'
|
||||
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
|
||||
|
||||
import { API_URL } from '../../../../../tools/configurations.js'
|
||||
import { fastifyErrors } from '../../../../../models/utils.js'
|
||||
import { API_URL } from '#src/tools/configurations.js'
|
||||
import { fastifyErrors } from '#src/models/utils.js'
|
||||
import { GOOGLE_BASE_URL, GOOGLE_CLIENT_ID } from '../__utils__/utils.js'
|
||||
|
||||
const querySchema = Type.Object({
|
||||
|
@ -1,19 +1,21 @@
|
||||
import tap from 'tap'
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import sinon from 'sinon'
|
||||
import jwt from 'jsonwebtoken'
|
||||
|
||||
import { application } from '../../../../application.js'
|
||||
import { authenticateUserTest } from '../../../../__test__/utils/authenticateUserTest.js'
|
||||
import prisma from '../../../../tools/database/prisma.js'
|
||||
import { refreshTokenExample } from '../../../../models/RefreshToken.js'
|
||||
import { expiresIn } from '../../../../tools/utils/jwtToken.js'
|
||||
import { application } from '#src/application.js'
|
||||
import { authenticateUserTest } from '#src/__test__/utils/authenticateUserTest.js'
|
||||
import prisma from '#src/tools/database/prisma.js'
|
||||
import { refreshTokenExample } from '#src/models/RefreshToken.js'
|
||||
import { expiresIn } from '#src/tools/utils/jwtToken.js'
|
||||
|
||||
await tap.test('POST /users/refresh-token', async (t) => {
|
||||
await test('POST /users/refresh-token', async (t) => {
|
||||
t.afterEach(() => {
|
||||
sinon.restore()
|
||||
})
|
||||
|
||||
await t.test('succeeds', async (t) => {
|
||||
await t.test('succeeds', async () => {
|
||||
const { refreshToken, refreshTokenStubValue } = await authenticateUserTest()
|
||||
sinon.stub(prisma, 'refreshToken').value({
|
||||
...refreshTokenStubValue,
|
||||
@ -31,13 +33,13 @@ await tap.test('POST /users/refresh-token', async (t) => {
|
||||
payload: { refreshToken }
|
||||
})
|
||||
const responseJson = response.json()
|
||||
t.equal(response.statusCode, 200)
|
||||
t.equal(responseJson.type, 'Bearer')
|
||||
t.equal(responseJson.expiresIn, expiresIn)
|
||||
t.type(responseJson.accessToken, 'string')
|
||||
assert.strictEqual(response.statusCode, 200)
|
||||
assert.strictEqual(responseJson.type, 'Bearer')
|
||||
assert.strictEqual(responseJson.expiresIn, expiresIn)
|
||||
assert.strictEqual(typeof responseJson.accessToken, 'string')
|
||||
})
|
||||
|
||||
await t.test('fails with refreshToken not saved in database', async (t) => {
|
||||
await t.test('fails with refreshToken not saved in database', async () => {
|
||||
sinon.stub(prisma, 'refreshToken').value({
|
||||
findFirst: async () => {
|
||||
return null
|
||||
@ -48,10 +50,10 @@ await tap.test('POST /users/refresh-token', async (t) => {
|
||||
url: '/users/refresh-token',
|
||||
payload: { refreshToken: 'somerandomtoken' }
|
||||
})
|
||||
t.equal(response.statusCode, 403)
|
||||
assert.strictEqual(response.statusCode, 403)
|
||||
})
|
||||
|
||||
await t.test('fails with invalid jwt refreshToken', async (t) => {
|
||||
await t.test('fails with invalid jwt refreshToken', async () => {
|
||||
const { refreshToken, refreshTokenStubValue } = await authenticateUserTest()
|
||||
sinon.stub(prisma, 'refreshToken').value({
|
||||
...refreshTokenStubValue,
|
||||
@ -67,6 +69,6 @@ await tap.test('POST /users/refresh-token', async (t) => {
|
||||
url: '/users/refresh-token',
|
||||
payload: { refreshToken }
|
||||
})
|
||||
t.equal(response.statusCode, 403)
|
||||
assert.strictEqual(response.statusCode, 403)
|
||||
})
|
||||
})
|
||||
|
@ -3,15 +3,15 @@ import { Type } from '@sinclair/typebox'
|
||||
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
|
||||
import jwt from 'jsonwebtoken'
|
||||
|
||||
import prisma from '../../../tools/database/prisma.js'
|
||||
import { fastifyErrors } from '../../../models/utils.js'
|
||||
import prisma from '#src/tools/database/prisma.js'
|
||||
import { fastifyErrors } from '#src/models/utils.js'
|
||||
import {
|
||||
generateAccessToken,
|
||||
jwtSchema,
|
||||
expiresIn
|
||||
} from '../../../tools/utils/jwtToken.js'
|
||||
import type { UserRefreshJWT } from '../../../models/User.js'
|
||||
import { JWT_REFRESH_SECRET } from '../../../tools/configurations.js'
|
||||
} from '#src/tools/utils/jwtToken.js'
|
||||
import type { UserRefreshJWT } from '#src/models/User.js'
|
||||
import { JWT_REFRESH_SECRET } from '#src/tools/configurations.js'
|
||||
|
||||
const bodyPostRefreshTokenSchema = Type.Object({
|
||||
refreshToken: jwtSchema.refreshToken
|
||||
|
@ -1,19 +1,21 @@
|
||||
import tap from 'tap'
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import sinon from 'sinon'
|
||||
import ms from 'ms'
|
||||
|
||||
import { application } from '../../../../application.js'
|
||||
import prisma from '../../../../tools/database/prisma.js'
|
||||
import { userExample } from '../../../../models/User.js'
|
||||
import { userSettingsExample } from '../../../../models/UserSettings.js'
|
||||
import { emailTransporter } from '../../../../tools/email/emailTransporter.js'
|
||||
import { application } from '#src/application.js'
|
||||
import prisma from '#src/tools/database/prisma.js'
|
||||
import { userExample } from '#src/models/User.js'
|
||||
import { userSettingsExample } from '#src/models/UserSettings.js'
|
||||
import { emailTransporter } from '#src/tools/email/emailTransporter.js'
|
||||
|
||||
await tap.test('POST /users/reset-password', async (t) => {
|
||||
await test('POST /users/reset-password', async (t) => {
|
||||
t.afterEach(() => {
|
||||
sinon.restore()
|
||||
})
|
||||
|
||||
await t.test('succeeds', async (t) => {
|
||||
await t.test('succeeds', async () => {
|
||||
sinon.stub(prisma, 'user').value({
|
||||
findUnique: async () => {
|
||||
return userExample
|
||||
@ -37,10 +39,10 @@ await tap.test('POST /users/reset-password', async (t) => {
|
||||
url: '/users/reset-password?redirectURI=https://redirecturi.com',
|
||||
payload: { email: userExample.email }
|
||||
})
|
||||
t.equal(response.statusCode, 200)
|
||||
assert.strictEqual(response.statusCode, 200)
|
||||
})
|
||||
|
||||
await t.test("fails with email that doesn't exist", async (t) => {
|
||||
await t.test("fails with email that doesn't exist", async () => {
|
||||
sinon.stub(prisma, 'user').value({
|
||||
findUnique: async () => {
|
||||
return null
|
||||
@ -51,10 +53,10 @@ await tap.test('POST /users/reset-password', async (t) => {
|
||||
url: '/users/reset-password?redirectURI=https://redirecturi.com',
|
||||
payload: { email: userExample.email }
|
||||
})
|
||||
t.equal(response.statusCode, 400)
|
||||
assert.strictEqual(response.statusCode, 400)
|
||||
})
|
||||
|
||||
await t.test('fails with unconfirmed account', async (t) => {
|
||||
await t.test('fails with unconfirmed account', async () => {
|
||||
sinon.stub(prisma, 'user').value({
|
||||
findUnique: async () => {
|
||||
return {
|
||||
@ -68,10 +70,10 @@ await tap.test('POST /users/reset-password', async (t) => {
|
||||
url: '/users/reset-password?redirectURI=https://redirecturi.com',
|
||||
payload: { email: userExample.email }
|
||||
})
|
||||
t.equal(response.statusCode, 400)
|
||||
assert.strictEqual(response.statusCode, 400)
|
||||
})
|
||||
|
||||
await t.test("fails if userSettings doesn't exist", async (t) => {
|
||||
await t.test("fails if userSettings doesn't exist", async () => {
|
||||
sinon.stub(prisma, 'user').value({
|
||||
findUnique: async () => {
|
||||
return userExample
|
||||
@ -87,10 +89,10 @@ await tap.test('POST /users/reset-password', async (t) => {
|
||||
url: '/users/reset-password?redirectURI=https://redirecturi.com',
|
||||
payload: { email: userExample.email }
|
||||
})
|
||||
t.equal(response.statusCode, 400)
|
||||
assert.strictEqual(response.statusCode, 400)
|
||||
})
|
||||
|
||||
await t.test('fails with a request already in progress', async (t) => {
|
||||
await t.test('fails with a request already in progress', async () => {
|
||||
sinon.stub(prisma, 'user').value({
|
||||
findUnique: async () => {
|
||||
return {
|
||||
@ -110,6 +112,6 @@ await tap.test('POST /users/reset-password', async (t) => {
|
||||
url: '/users/reset-password?redirectURI=https://redirecturi.com',
|
||||
payload: { email: userExample.email }
|
||||
})
|
||||
t.equal(response.statusCode, 400)
|
||||
assert.strictEqual(response.statusCode, 400)
|
||||
})
|
||||
})
|
||||
|
@ -1,17 +1,19 @@
|
||||
import tap from 'tap'
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import sinon from 'sinon'
|
||||
import ms from 'ms'
|
||||
|
||||
import { application } from '../../../../application.js'
|
||||
import prisma from '../../../../tools/database/prisma.js'
|
||||
import { userExample } from '../../../../models/User.js'
|
||||
import { application } from '#src/application.js'
|
||||
import prisma from '#src/tools/database/prisma.js'
|
||||
import { userExample } from '#src/models/User.js'
|
||||
|
||||
await tap.test('PUT /users/reset-password', async (t) => {
|
||||
await test('PUT /users/reset-password', async (t) => {
|
||||
t.afterEach(() => {
|
||||
sinon.restore()
|
||||
})
|
||||
|
||||
await t.test('succeeds', async (t) => {
|
||||
await t.test('succeeds', async () => {
|
||||
const temporaryToken = 'random-token'
|
||||
sinon.stub(prisma, 'user').value({
|
||||
findFirst: async () => {
|
||||
@ -38,10 +40,10 @@ await tap.test('PUT /users/reset-password', async (t) => {
|
||||
temporaryToken: userExample.temporaryToken
|
||||
}
|
||||
})
|
||||
t.equal(response.statusCode, 200)
|
||||
assert.strictEqual(response.statusCode, 200)
|
||||
})
|
||||
|
||||
await t.test('fails with expired temporaryToken', async (t) => {
|
||||
await t.test('fails with expired temporaryToken', async () => {
|
||||
const temporaryToken = 'random-token'
|
||||
sinon.stub(prisma, 'user').value({
|
||||
findFirst: async () => {
|
||||
@ -63,6 +65,6 @@ await tap.test('PUT /users/reset-password', async (t) => {
|
||||
temporaryToken: userExample.temporaryToken
|
||||
}
|
||||
})
|
||||
t.equal(response.statusCode, 400)
|
||||
assert.strictEqual(response.statusCode, 400)
|
||||
})
|
||||
})
|
||||
|
@ -5,11 +5,11 @@ import { Type } from '@sinclair/typebox'
|
||||
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
|
||||
import ms from 'ms'
|
||||
|
||||
import prisma from '../../../tools/database/prisma.js'
|
||||
import { fastifyErrors } from '../../../models/utils.js'
|
||||
import { userSchema } from '../../../models/User.js'
|
||||
import { sendEmail } from '../../../tools/email/sendEmail.js'
|
||||
import type { Language, Theme } from '../../../models/UserSettings.js'
|
||||
import prisma from '#src/tools/database/prisma.js'
|
||||
import { fastifyErrors } from '#src/models/utils.js'
|
||||
import { userSchema } from '#src/models/User.js'
|
||||
import { sendEmail } from '#src/tools/email/sendEmail.js'
|
||||
import type { Language, Theme } from '#src/models/UserSettings.js'
|
||||
|
||||
const queryPostResetPasswordSchema = Type.Object({
|
||||
redirectURI: Type.String({ format: 'uri-reference' })
|
||||
|
@ -3,9 +3,9 @@ import { Type } from '@sinclair/typebox'
|
||||
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
|
||||
import bcrypt from 'bcryptjs'
|
||||
|
||||
import prisma from '../../../tools/database/prisma.js'
|
||||
import { fastifyErrors } from '../../../models/utils.js'
|
||||
import { userSchema } from '../../../models/User.js'
|
||||
import prisma from '#src/tools/database/prisma.js'
|
||||
import { fastifyErrors } from '#src/models/utils.js'
|
||||
import { userSchema } from '#src/models/User.js'
|
||||
|
||||
const bodyPutResetPasswordSchema = Type.Object({
|
||||
password: userSchema.password,
|
||||
|
@ -1,24 +1,26 @@
|
||||
import tap from 'tap'
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import sinon from 'sinon'
|
||||
import bcrypt from 'bcryptjs'
|
||||
|
||||
import { application } from '../../../../application.js'
|
||||
import prisma from '../../../../tools/database/prisma.js'
|
||||
import { userExample } from '../../../../models/User.js'
|
||||
import { refreshTokenExample } from '../../../../models/RefreshToken.js'
|
||||
import { expiresIn } from '../../../../tools/utils/jwtToken.js'
|
||||
import { application } from '#src/application.js'
|
||||
import prisma from '#src/tools/database/prisma.js'
|
||||
import { userExample } from '#src/models/User.js'
|
||||
import { refreshTokenExample } from '#src/models/RefreshToken.js'
|
||||
import { expiresIn } from '#src/tools/utils/jwtToken.js'
|
||||
|
||||
const payload = {
|
||||
email: userExample.email,
|
||||
password: userExample.password
|
||||
}
|
||||
|
||||
await tap.test('POST /users/signin', async (t) => {
|
||||
await test('POST /users/signin', async (t) => {
|
||||
t.afterEach(() => {
|
||||
sinon.restore()
|
||||
})
|
||||
|
||||
await t.test('succeeds', async (t) => {
|
||||
await t.test('succeeds', async () => {
|
||||
sinon.stub(prisma, 'user').value({
|
||||
findUnique: async () => {
|
||||
return {
|
||||
@ -38,12 +40,12 @@ await tap.test('POST /users/signin', async (t) => {
|
||||
payload
|
||||
})
|
||||
const responseJson = response.json()
|
||||
t.equal(response.statusCode, 200)
|
||||
t.equal(responseJson.type, 'Bearer')
|
||||
t.equal(responseJson.expiresIn, expiresIn)
|
||||
assert.strictEqual(response.statusCode, 200)
|
||||
assert.strictEqual(responseJson.type, 'Bearer')
|
||||
assert.strictEqual(responseJson.expiresIn, expiresIn)
|
||||
})
|
||||
|
||||
await t.test('fails with invalid user', async (t) => {
|
||||
await t.test('fails with invalid user', async () => {
|
||||
sinon.stub(prisma, 'user').value({
|
||||
findUnique: () => {
|
||||
return null
|
||||
@ -54,10 +56,10 @@ await tap.test('POST /users/signin', async (t) => {
|
||||
url: '/users/signin',
|
||||
payload
|
||||
})
|
||||
t.equal(response.statusCode, 400)
|
||||
assert.strictEqual(response.statusCode, 400)
|
||||
})
|
||||
|
||||
await t.test('fails with invalid email', async (t) => {
|
||||
await t.test('fails with invalid email', async () => {
|
||||
sinon.stub(prisma, 'user').value({
|
||||
findUnique: () => {
|
||||
return null
|
||||
@ -71,10 +73,10 @@ await tap.test('POST /users/signin', async (t) => {
|
||||
email: 'incorrect-email'
|
||||
}
|
||||
})
|
||||
t.equal(response.statusCode, 400)
|
||||
assert.strictEqual(response.statusCode, 400)
|
||||
})
|
||||
|
||||
await t.test("fails if user hasn't got a password", async (t) => {
|
||||
await t.test("fails if user hasn't got a password", async () => {
|
||||
sinon.stub(prisma, 'user').value({
|
||||
findUnique: () => {
|
||||
return {
|
||||
@ -88,10 +90,10 @@ await tap.test('POST /users/signin', async (t) => {
|
||||
url: '/users/signin',
|
||||
payload
|
||||
})
|
||||
t.equal(response.statusCode, 400)
|
||||
assert.strictEqual(response.statusCode, 400)
|
||||
})
|
||||
|
||||
await t.test('fails with incorrect password', async (t) => {
|
||||
await t.test('fails with incorrect password', async () => {
|
||||
sinon.stub(prisma, 'user').value({
|
||||
findUnique: async () => {
|
||||
return userExample
|
||||
@ -105,6 +107,6 @@ await tap.test('POST /users/signin', async (t) => {
|
||||
password: 'incorrect-password'
|
||||
}
|
||||
})
|
||||
t.equal(response.statusCode, 400)
|
||||
assert.strictEqual(response.statusCode, 400)
|
||||
})
|
||||
})
|
||||
|
@ -3,15 +3,15 @@ import { Type } from '@sinclair/typebox'
|
||||
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
|
||||
import bcrypt from 'bcryptjs'
|
||||
|
||||
import prisma from '../../../tools/database/prisma.js'
|
||||
import { fastifyErrors } from '../../../models/utils.js'
|
||||
import { userSchema } from '../../../models/User.js'
|
||||
import prisma from '#src/tools/database/prisma.js'
|
||||
import { fastifyErrors } from '#src/models/utils.js'
|
||||
import { userSchema } from '#src/models/User.js'
|
||||
import {
|
||||
generateAccessToken,
|
||||
generateRefreshToken,
|
||||
jwtSchema,
|
||||
expiresIn
|
||||
} from '../../../tools/utils/jwtToken.js'
|
||||
} from '#src/tools/utils/jwtToken.js'
|
||||
|
||||
const bodyPostSigninSchema = Type.Object({
|
||||
email: userSchema.email,
|
||||
|
@ -1,16 +1,18 @@
|
||||
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 { application } from '#src/application.js'
|
||||
import { authenticateUserTest } from '#src/__test__/utils/authenticateUserTest.js'
|
||||
import prisma from '#src/tools/database/prisma.js'
|
||||
|
||||
await tap.test('DELETE /users/signout', async (t) => {
|
||||
await test('DELETE /users/signout', async (t) => {
|
||||
t.afterEach(() => {
|
||||
sinon.restore()
|
||||
})
|
||||
|
||||
await t.test('succeeds', async (t) => {
|
||||
await t.test('succeeds', async () => {
|
||||
const { accessToken, refreshTokenStubValue } = await authenticateUserTest()
|
||||
sinon.stub(prisma, 'refreshToken').value({
|
||||
...refreshTokenStubValue,
|
||||
@ -25,14 +27,14 @@ await tap.test('DELETE /users/signout', async (t) => {
|
||||
authorization: `Bearer ${accessToken}`
|
||||
}
|
||||
})
|
||||
t.equal(response.statusCode, 200)
|
||||
assert.strictEqual(response.statusCode, 200)
|
||||
})
|
||||
|
||||
await t.test('fails with empty authorized header', async (t) => {
|
||||
await t.test('fails with empty authorized header', async () => {
|
||||
const response = await application.inject({
|
||||
method: 'DELETE',
|
||||
url: '/users/signout'
|
||||
})
|
||||
t.equal(response.statusCode, 401)
|
||||
assert.strictEqual(response.statusCode, 401)
|
||||
})
|
||||
})
|
||||
|
@ -1,18 +1,20 @@
|
||||
import tap from 'tap'
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import sinon from 'sinon'
|
||||
import jwt from 'jsonwebtoken'
|
||||
|
||||
import { application } from '../../../../application.js'
|
||||
import prisma from '../../../../tools/database/prisma.js'
|
||||
import { refreshTokenExample } from '../../../../models/RefreshToken.js'
|
||||
import type { UserRefreshJWT } from '../../../../models/User.js'
|
||||
import { application } from '#src/application.js'
|
||||
import prisma from '#src/tools/database/prisma.js'
|
||||
import { refreshTokenExample } from '#src/models/RefreshToken.js'
|
||||
import type { UserRefreshJWT } from '#src/models/User.js'
|
||||
|
||||
await tap.test('POST /users/signout', async (t) => {
|
||||
await test('POST /users/signout', async (t) => {
|
||||
t.afterEach(() => {
|
||||
sinon.restore()
|
||||
})
|
||||
|
||||
await t.test('succeeds', async (t) => {
|
||||
await t.test('succeeds', async () => {
|
||||
sinon.stub(prisma, 'refreshToken').value({
|
||||
findFirst: async () => {
|
||||
return refreshTokenExample
|
||||
@ -32,10 +34,10 @@ await tap.test('POST /users/signout', async (t) => {
|
||||
url: '/users/signout',
|
||||
payload: { refreshToken: 'jwt token' }
|
||||
})
|
||||
t.equal(response.statusCode, 200)
|
||||
assert.strictEqual(response.statusCode, 200)
|
||||
})
|
||||
|
||||
await t.test('fails with invalid refreshToken', async (t) => {
|
||||
await t.test('fails with invalid refreshToken', async () => {
|
||||
sinon.stub(prisma, 'refreshToken').value({
|
||||
findFirst: async () => {
|
||||
return null
|
||||
@ -46,6 +48,6 @@ await tap.test('POST /users/signout', async (t) => {
|
||||
url: '/users/signout',
|
||||
payload: { refreshToken: 'somerandomtoken' }
|
||||
})
|
||||
t.equal(response.statusCode, 404)
|
||||
assert.strictEqual(response.statusCode, 404)
|
||||
})
|
||||
})
|
||||
|
@ -1,9 +1,9 @@
|
||||
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 prisma from '#src/tools/database/prisma.js'
|
||||
import { fastifyErrors } from '#src/models/utils.js'
|
||||
import authenticateUser from '#src/tools/plugins/authenticateUser.js'
|
||||
|
||||
const deleteSignoutSchema: FastifySchema = {
|
||||
description: 'Signout the user to every connected devices',
|
||||
|
@ -3,11 +3,11 @@ import { Type } from '@sinclair/typebox'
|
||||
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
|
||||
import jwt from 'jsonwebtoken'
|
||||
|
||||
import prisma from '../../../tools/database/prisma.js'
|
||||
import { fastifyErrors } from '../../../models/utils.js'
|
||||
import { JWT_REFRESH_SECRET } from '../../../tools/configurations.js'
|
||||
import type { UserRefreshJWT } from '../../../models/User.js'
|
||||
import { jwtSchema } from '../../../tools/utils/jwtToken.js'
|
||||
import prisma from '#src/tools/database/prisma.js'
|
||||
import { fastifyErrors } from '#src/models/utils.js'
|
||||
import { JWT_REFRESH_SECRET } from '#src/tools/configurations.js'
|
||||
import type { UserRefreshJWT } from '#src/models/User.js'
|
||||
import { jwtSchema } from '#src/tools/utils/jwtToken.js'
|
||||
|
||||
const bodyPostSignoutSchema = Type.Object({
|
||||
refreshToken: jwtSchema.refreshToken
|
||||
|
@ -1,11 +1,13 @@
|
||||
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 prisma from '../../../../tools/database/prisma.js'
|
||||
import { userExample } from '../../../../models/User.js'
|
||||
import { userSettingsExample } from '../../../../models/UserSettings.js'
|
||||
import { emailTransporter } from '../../../../tools/email/emailTransporter.js'
|
||||
import { application } from '#src/application.js'
|
||||
import prisma from '#src/tools/database/prisma.js'
|
||||
import { userExample } from '#src/models/User.js'
|
||||
import { userSettingsExample } from '#src/models/UserSettings.js'
|
||||
import { emailTransporter } from '#src/tools/email/emailTransporter.js'
|
||||
|
||||
const payload = {
|
||||
name: userExample.name,
|
||||
@ -15,12 +17,12 @@ const payload = {
|
||||
language: userSettingsExample.language
|
||||
}
|
||||
|
||||
await tap.test('POST /users/signup', async (t) => {
|
||||
await test('POST /users/signup', async (t) => {
|
||||
t.afterEach(() => {
|
||||
sinon.restore()
|
||||
})
|
||||
|
||||
await t.test('succeeds', async (t) => {
|
||||
await t.test('succeeds', async () => {
|
||||
sinon.stub(prisma, 'user').value({
|
||||
findFirst: async () => {
|
||||
return null
|
||||
@ -41,12 +43,12 @@ await tap.test('POST /users/signup', async (t) => {
|
||||
payload
|
||||
})
|
||||
const responseJson = response.json()
|
||||
t.equal(response.statusCode, 201)
|
||||
t.equal(responseJson.user.name, userExample.name)
|
||||
t.equal(responseJson.user.email, userExample.email)
|
||||
assert.strictEqual(response.statusCode, 201)
|
||||
assert.strictEqual(responseJson.user.name, userExample.name)
|
||||
assert.strictEqual(responseJson.user.email, userExample.email)
|
||||
})
|
||||
|
||||
await t.test('fails with invalid email', async (t) => {
|
||||
await t.test('fails with invalid email', async () => {
|
||||
sinon.stub(prisma, 'user').value({
|
||||
findFirst: async () => {
|
||||
return null
|
||||
@ -61,10 +63,10 @@ await tap.test('POST /users/signup', async (t) => {
|
||||
email: 'incorrect-email@abc'
|
||||
}
|
||||
})
|
||||
t.equal(response.statusCode, 400)
|
||||
assert.strictEqual(response.statusCode, 400)
|
||||
})
|
||||
|
||||
await t.test('fails with already taken `name` or `email`', async (t) => {
|
||||
await t.test('fails with already taken `name` or `email`', async () => {
|
||||
sinon.stub(prisma, 'user').value({
|
||||
findFirst: async () => {
|
||||
return userExample
|
||||
@ -76,6 +78,6 @@ await tap.test('POST /users/signup', async (t) => {
|
||||
url: '/users/signup',
|
||||
payload
|
||||
})
|
||||
t.equal(response.statusCode, 400)
|
||||
assert.strictEqual(response.statusCode, 400)
|
||||
})
|
||||
})
|
||||
|
@ -5,12 +5,12 @@ import { Type } from '@sinclair/typebox'
|
||||
import bcrypt from 'bcryptjs'
|
||||
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
|
||||
|
||||
import prisma from '../../../tools/database/prisma.js'
|
||||
import { fastifyErrors } from '../../../models/utils.js'
|
||||
import type { BodyUserSchemaType } from '../../../models/User.js'
|
||||
import { bodyUserSchema, userPublicSchema } from '../../../models/User.js'
|
||||
import { sendEmail } from '../../../tools/email/sendEmail.js'
|
||||
import { API_URL } from '../../../tools/configurations.js'
|
||||
import prisma from '#src/tools/database/prisma.js'
|
||||
import { fastifyErrors } from '#src/models/utils.js'
|
||||
import type { BodyUserSchemaType } from '#src/models/User.js'
|
||||
import { bodyUserSchema, userPublicSchema } from '#src/models/User.js'
|
||||
import { sendEmail } from '#src/tools/email/sendEmail.js'
|
||||
import { API_URL } from '#src/tools/configurations.js'
|
||||
|
||||
const queryPostSignupSchema = Type.Object({
|
||||
redirectURI: Type.Optional(Type.String({ format: 'uri-reference' }))
|
||||
|
Reference in New Issue
Block a user