Skip to content

Commit

Permalink
Migrated queries to knex methods in users/list.test.ts (#1507)
Browse files Browse the repository at this point in the history
Co-authored-by: Gonzalo Fourtané Odisea <154799410+ghOdisea@users.noreply.github.com>
  • Loading branch information
ClaudioMartinH and ghOdisea authored Oct 28, 2024
1 parent 9693313 commit 1f3a762
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 33 deletions.
10 changes: 8 additions & 2 deletions services/sso/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file.

# Changelog

## [1.49.0] - 2024-10-28

### Changed

- Updated `dashboard/users/list.test.ts` to Knex methods.

## [1.48.0] - 2024-10-28

### Changed
Expand All @@ -19,13 +25,13 @@ All notable changes to this project will be documented in this file.

### Changed

- Updated all Typescript types to it's corresponding TTypeNames.
- Updated test suite `__tests__/users/list.test.ts` queries to Knex methods.

## [1.45.00] - 2024-10-15

### Changed

- Updated `dashboard/users/batchDelete.test ` to Knex.
- Updated `dashboard/users/batchDelete.test` to Knex.
- Replaced `client.query` with Knex methods (`whereIn`, `select`).

## [1.44.0] - 2024-10-15
Expand Down
4 changes: 1 addition & 3 deletions services/sso/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"name": "sso-service",

"version": "1.47.0",

"version": "1.49.0",
"description": "",
"directories": {
"test": "test"
Expand Down
57 changes: 29 additions & 28 deletions services/sso/src/__tests__/users/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,37 @@ import qs from 'qs'
import { userSchema } from '../../schemas'
import { server, testUserData } from '../globalSetup'
import { pathRoot } from '../../routes/routes'
import { client } from '../../db/client'
import db from '../../db/knexClient'

const route = `${pathRoot.v1.users}`
const adminIdData = await client.query(
'SELECT id FROM "user" WHERE dni IN ($1) ',
[testUserData.admin.dni]
)
const userIdData = await client.query(
'SELECT id FROM "user" WHERE dni IN ($1) ',
[testUserData.user.dni]
)
const deletedUserIdData = await client.query(
'SELECT id FROM "user" WHERE dni IN ($1) ',
[testUserData.userToDelete.dni]
)
const { id } = adminIdData.rows[0]
const { id: userId } = userIdData.rows[0]
const { id: deletedUserId } = deletedUserIdData.rows[0]

const adminIdData = await db('user')
.select('id')
.where({ dni: testUserData.admin.dni })
.first()
const userIdData = await db('user')
.select('id')
.where({ dni: testUserData.user.dni })
.first()
const deletedUserIdData = await db('user')
.select('id')
.where({ dni: testUserData.userToDelete.dni })
.first()
const { id } = adminIdData
const { id: userId } = userIdData
const { id: deletedUserId } = deletedUserIdData

const responseSchema = userSchema.pick({ id: true, name: true }).array()

const stringData = (data: string[]) =>
qs.stringify(
{ id: data, fields: ['id', 'name'] },
{ indices: false, arrayFormat: 'comma' }
)
afterEach(async () => {
await client.query('UPDATE "user" SET deleted_at = $1 WHERE dni = $2', [
null,
testUserData.userToDelete.dni,
])
await db('user')
.update({ deleted_at: null })
.where({ dni: testUserData.userToDelete.dni })
})
describe('Testing get users name by Id endpoint', () => {
it('returns a user successfully with a single valid ID', async () => {
Expand Down Expand Up @@ -84,10 +86,10 @@ describe('Testing get users name by Id endpoint', () => {
})

it('returns an empty array if the user is deleted', async () => {
await client.query(
'UPDATE "user" SET deleted_at = CURRENT_TIMESTAMP WHERE dni = $1',
[testUserData.userToDelete.dni]
)
await db('user')
.update({ deleted_at: new Date() })
.where({ dni: testUserData.userToDelete.dni })

const response = await supertest(server).get(
`${route}?${stringData([deletedUserId])}`
)
Expand All @@ -96,10 +98,9 @@ describe('Testing get users name by Id endpoint', () => {
})

it('returns just the not deleted user', async () => {
await client.query(
'UPDATE "user" SET deleted_at = CURRENT_TIMESTAMP WHERE dni = $1',
[testUserData.userToDelete.dni]
)
await db('user')
.update({ deleted_at: new Date() })
.where({ dni: testUserData.userToDelete.dni })
const response = await supertest(server).get(
`${route}?${stringData([deletedUserId, id])}`
)
Expand Down

0 comments on commit 1f3a762

Please sign in to comment.