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

@ -3,10 +3,10 @@ import {
expiresIn,
generateAccessToken,
generateRefreshToken
} from './jwtToken.js'
import prisma from '../database/prisma.js'
import type { ProviderOAuth } from '../../models/OAuth.js'
import type { UserRequest } from '../../models/User.js'
} from '#src/tools/utils/jwtToken.js'
import prisma from '#src/tools/database/prisma.js'
import type { ProviderOAuth } from '#src/models/OAuth.js'
import type { UserRequest } from '#src/models/User.js'
interface ProviderData {
name: string

View File

@ -1,21 +1,23 @@
import tap from 'tap'
import test from 'node:test'
import assert from 'node:assert/strict'
import sinon from 'sinon'
import { userExample } from '../../../models/User.js'
import { userSettingsExample } from '../../../models/UserSettings.js'
import { OAuthStrategy } from '../OAuthStrategy.js'
import prisma from '../../database/prisma.js'
import { refreshTokenExample } from '../../../models/RefreshToken.js'
import { userExample } from '#src/models/User.js'
import { userSettingsExample } from '#src/models/UserSettings.js'
import { OAuthStrategy } from '#src/tools/utils/OAuthStrategy.js'
import prisma from '#src/tools/database/prisma.js'
import { refreshTokenExample } from '#src/models/RefreshToken.js'
const oauthStrategy = new OAuthStrategy('Discord')
await tap.test('tools/utils/OAuthStrategy', async (t) => {
await test('tools/utils/OAuthStrategy', async (t) => {
await t.test('callbackSignin', async (t) => {
t.afterEach(() => {
sinon.restore()
})
await t.test('should signup the user', async (t) => {
await t.test('should signup the user', async () => {
const name = 'Martin'
const id = '12345'
sinon.stub(prisma, 'user').value({
@ -60,7 +62,7 @@ await tap.test('tools/utils/OAuthStrategy', async (t) => {
const userCreateSpy = sinon.spy(prisma.user, 'create')
const userSettingCreateSpy = sinon.spy(prisma.userSetting, 'create')
await oauthStrategy.callbackSignin({ id, name })
t.equal(
assert.strictEqual(
oAuthCreateSpy.calledWith({
data: {
userId: userExample.id,
@ -70,7 +72,7 @@ await tap.test('tools/utils/OAuthStrategy', async (t) => {
}),
true
)
t.equal(
assert.strictEqual(
oAuthFindFirstSpy.calledWith({
where: {
provider: 'Discord',
@ -79,9 +81,9 @@ await tap.test('tools/utils/OAuthStrategy', async (t) => {
}),
true
)
t.equal(userCountSpy.calledWith({ where: { name } }), true)
t.equal(userCreateSpy.calledWith({ data: { name } }), true)
t.equal(
assert.strictEqual(userCountSpy.calledWith({ where: { name } }), true)
assert.strictEqual(userCreateSpy.calledWith({ data: { name } }), true)
assert.strictEqual(
userSettingCreateSpy.calledWith({
data: {
userId: userExample.id
@ -97,7 +99,7 @@ await tap.test('tools/utils/OAuthStrategy', async (t) => {
sinon.restore()
})
await t.test('should add the strategy to the user', async (t) => {
await t.test('should add the strategy to the user', async () => {
const name = userExample.name
const id = '12345'
sinon.stub(prisma, 'oAuth').value({
@ -121,8 +123,8 @@ await tap.test('tools/utils/OAuthStrategy', async (t) => {
{ id, name },
{ accessToken: '123', current: userExample, currentStrategy: 'Local' }
)
t.equal(result, 'success')
t.equal(
assert.strictEqual(result, 'success')
assert.strictEqual(
oAuthCreateSpy.calledWith({
data: {
userId: userExample.id,
@ -132,7 +134,7 @@ await tap.test('tools/utils/OAuthStrategy', async (t) => {
}),
true
)
t.equal(
assert.strictEqual(
oAuthFindFirstSpy.calledWith({
where: {
provider: 'Discord',
@ -145,7 +147,7 @@ await tap.test('tools/utils/OAuthStrategy', async (t) => {
await t.test(
'should not add the strategy if the account of the provider is already used',
async (t) => {
async () => {
const name = userExample.name
const id = '12345'
sinon.stub(prisma, 'oAuth').value({
@ -165,8 +167,11 @@ await tap.test('tools/utils/OAuthStrategy', async (t) => {
{ id, name },
{ accessToken: '123', current: userExample, currentStrategy: 'Local' }
)
t.equal(result, 'This account is already used by someone else')
t.equal(
assert.strictEqual(
result,
'This account is already used by someone else'
)
assert.strictEqual(
oAuthFindFirstSpy.calledWith({
where: {
provider: 'Discord',
@ -180,7 +185,7 @@ await tap.test('tools/utils/OAuthStrategy', async (t) => {
await t.test(
'should not add the strategy if the user is already connected with it',
async (t) => {
async () => {
const name = userExample.name
const id = '12345'
sinon.stub(prisma, 'oAuth').value({
@ -200,8 +205,8 @@ await tap.test('tools/utils/OAuthStrategy', async (t) => {
{ id, name },
{ accessToken: '123', current: userExample, currentStrategy: 'Local' }
)
t.equal(result, 'You are already using this account')
t.equal(
assert.strictEqual(result, 'You are already using this account')
assert.strictEqual(
oAuthFindFirstSpy.calledWith({
where: {
provider: 'Discord',

View File

@ -1,21 +1,22 @@
import tap from 'tap'
import test from 'node:test'
import assert from 'node:assert/strict'
import { buildQueryURL } from '../buildQueryURL.js'
await tap.test('tools/utils/buildQueryUrl', async (t) => {
t.equal(
await test('tools/utils/buildQueryUrl', async () => {
assert.strictEqual(
buildQueryURL('http://localhost:8080', {
test: 'query'
}),
'http://localhost:8080/?test=query'
)
t.equal(
assert.strictEqual(
buildQueryURL('http://localhost:8080/', {
test: 'query'
}),
'http://localhost:8080/?test=query'
)
t.equal(
assert.strictEqual(
buildQueryURL('http://localhost:3000', {
test: 'query',
code: 'abc'

View File

@ -1,27 +1,31 @@
import tap from 'tap'
import test from 'node:test'
import assert from 'node:assert/strict'
import { parseStringNullish } from '../parseStringNullish.js'
const defaultString = 'defaultString'
await tap.test('tools/utils/parseStringNullish', async (t) => {
await test('tools/utils/parseStringNullish', async (t) => {
await t.test(
'returns `defaultString` if `string === undefined`',
async (t) => {
t.equal(parseStringNullish(defaultString, undefined), defaultString)
async () => {
assert.strictEqual(
parseStringNullish(defaultString, undefined),
defaultString
)
}
)
await t.test('returns `null` if `string === null`', async (t) => {
t.equal(parseStringNullish(defaultString, null), null)
await t.test('returns `null` if `string === null`', async () => {
assert.strictEqual(parseStringNullish(defaultString, null), null)
})
await t.test('returns `null` if `string.length === 0`', async (t) => {
t.equal(parseStringNullish(defaultString, ''), null)
await t.test('returns `null` if `string.length === 0`', async () => {
assert.strictEqual(parseStringNullish(defaultString, ''), null)
})
await t.test('returns `string` if `string.length > 0`', async (t) => {
await t.test('returns `string` if `string.length > 0`', async () => {
const string = 'myString'
t.equal(parseStringNullish(defaultString, string), string)
assert.strictEqual(parseStringNullish(defaultString, string), string)
})
})

View File

@ -9,8 +9,8 @@ export const buildQueryURL = (
queryObject: ObjectAny
): string => {
const url = new URL(baseURL)
Object.entries(queryObject).forEach(([query, value]) => {
for (const [query, value] of Object.entries(queryObject)) {
url.searchParams.append(query, value)
})
}
return url.href
}

View File

@ -4,13 +4,13 @@ import { Type } from '@sinclair/typebox'
import jwt from 'jsonwebtoken'
import ms from 'ms'
import prisma from '../database/prisma.js'
import type { UserJWT } from '../../models/User.js'
import prisma from '#src/tools/database/prisma.js'
import type { UserJWT } from '#src/models/User.js'
import {
JWT_ACCESS_EXPIRES_IN,
JWT_ACCESS_SECRET,
JWT_REFRESH_SECRET
} from '../configurations.js'
} from '#src/tools/configurations.js'
export interface ResponseJWT {
accessToken: string

View File

@ -8,7 +8,7 @@ import type { SavedMultipartFile } from '@fastify/multipart'
import {
FILE_UPLOADS_API_KEY,
FILE_UPLOADS_API_URL
} from '../configurations.js'
} from '#src/tools/configurations.js'
export const fileUploadAPI = axios.create({
baseURL: FILE_UPLOADS_API_URL,
@ -44,6 +44,7 @@ export const uploadFile = async (
}
})
} catch (error) {
console.error(error)
throw fastify.httpErrors.requestHeaderFieldsTooLarge(
`File should be less than ${MAXIMUM_FILE_SIZE}mb.`
)