Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate to knex updateStatus.test #1523

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion services/sso/openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
info:
version: 1.46.0
version: 1.48.0
title: IT Academy SSO Service
description: This is an SSO service that is used across all ITA services.
openapi: 3.0.0
Expand Down
4 changes: 2 additions & 2 deletions services/sso/src/__tests__/dashboard/auth/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Testing authentication endpoint', () => {
})
expect(response.status).toBe(204)

const cookie = response.header['set-cookie'] as string[]
const cookie = response.header['set-cookie']
expect(cookie[0]).toMatch(/authToken/)
expect(cookie[1]).toMatch(/refreshToken/)
})
Expand All @@ -25,7 +25,7 @@ describe('Testing authentication endpoint', () => {
})
expect(response.status).toBe(204)

const cookie = response.header['set-cookie'] as string[]
const cookie = response.header['set-cookie']
expect(cookie[0]).toMatch(/authToken/)
expect(cookie[1]).toMatch(/refreshToken/)
})
Expand Down
40 changes: 15 additions & 25 deletions services/sso/src/__tests__/dashboard/users/updateStatus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { afterEach, beforeAll, describe, expect, it } from 'vitest'
import { pathRoot } from '../../../routes/routes'
import { server, testUserData } from '../../globalSetup'
import { UserStatus } from '../../../schemas/users/userSchema'
import { client } from '../../../db/client'
import db from '../../../db/knexClient'
import { dashboardLoginAndGetToken } from '../../helpers/testHelpers'

const route = `${pathRoot.v1.dashboard.users}/status`
Expand All @@ -21,20 +21,19 @@ beforeAll(async () => {
testUserData.mentor.password
)
})

afterEach(async () => {
const restorePromises = [
testUserData.blockedUser,
testUserData.mentor,
testUserData.pendingUser,
testUserData.user,
].map(async ({ id, status }) => {
await client.query('UPDATE "user" SET status = $1 WHERE id = $2', [
status,
id,
])
await db('user').update('status', status).where('id', id)
})
await Promise.all(restorePromises)
})

describe('Testing POST dashboard/users/status endpoint', () => {
it('should return 204 when successfully updating multiple users to BLOCKED status', async () => {
const reqBody = {
Expand All @@ -47,15 +46,15 @@ describe('Testing POST dashboard/users/status endpoint', () => {
.send(reqBody)
expect(response.status).toBe(204)
const promises = reqBody.ids.map(async (id) => {
const result = await client.query(
'SELECT status FROM "user" WHERE id = $1',
[id]
)
expect(result.rows[0].status).toBe(UserStatus.BLOCKED)
const result = await db('user').select('status').where({ id }).first()

// 'SELECT status FROM "user" WHERE id = $1',[id]
expect(result.status).toBe(UserStatus.BLOCKED)
})

await Promise.all(promises)
})

it('should return 204 when successfully updating multiple users to ACTIVE status', async () => {
const reqBody = {
ids: [testUserData.blockedUser.id, testUserData.pendingUser.id],
Expand All @@ -67,11 +66,8 @@ describe('Testing POST dashboard/users/status endpoint', () => {
.send(reqBody)
expect(response.status).toBe(204)
const promises = reqBody.ids.map(async (id) => {
const result = await client.query(
'SELECT status FROM "user" WHERE id = $1',
[id]
)
expect(result.rows[0].status).toBe(UserStatus.ACTIVE)
const result = await db('user').where({ id }).select('status').first()
expect(result.status).toBe(UserStatus.ACTIVE)
})
await Promise.all(promises)
})
Expand All @@ -90,11 +86,8 @@ describe('Testing POST dashboard/users/status endpoint', () => {
expect(response.body.message).toBe(
'nbwp5he40j70jmywqjevijc6,nbwp5he40j70jmywqjevijc4 not found'
)
const result = await client.query(
'SELECT status FROM "user" WHERE id = $1',
[id]
)
expect(result.rows[0].status).toBe(UserStatus.ACTIVE)
const result = await db('user').where({ id }).select('status').first()
expect(result.status).toBe(UserStatus.ACTIVE)
})

it('should return 204 when successfully updating a user to ACTIVE status with a mentor token', async () => {
Expand All @@ -108,11 +101,8 @@ describe('Testing POST dashboard/users/status endpoint', () => {
.send(reqBody)
expect(response.status).toBe(204)
const promises = reqBody.ids.map(async (id) => {
const result = await client.query(
'SELECT status FROM "user" WHERE id = $1',
[id]
)
expect(result.rows[0].status).toBe(UserStatus.ACTIVE)
const result = await db('user').where({ id }).select('status').first()
expect(result.status).toBe(UserStatus.ACTIVE)
})
await Promise.all(promises)
})
Expand Down
Loading