1+ const { describe, before, after, test } = require ( 'node:test' )
2+ const assert = require ( 'node:assert' )
13const buildServer = require ( './build-server' )
24
35const plugin = require ( '../plugin.js' )
@@ -7,9 +9,10 @@ const { getPool } = require('./utils')
79describe ( 'fastify-mssql' , ( ) => {
810 let app
911
10- beforeAll ( async ( ) => {
12+ before ( async ( ) => {
1113 const pool = await getPool ( )
1214 app = buildServer ( )
15+
1316 await pool . query ( `
1417 IF NOT EXISTS (SELECT 1 FROM sys.databases WHERE name = 'TestSuite')
1518 CREATE DATABASE TestSuite;
@@ -24,17 +27,7 @@ describe('fastify-mssql', () => {
2427 await pool . query (
2528 "INSERT INTO [dbo].[Users] ([id], [name], [email]) VALUES ('2', N'fizzbuzz', N'fizzbuzz@gmail.com');"
2629 )
27- } )
28-
29- afterAll ( async ( ) => {
30- const pool = await getPool ( )
31- await pool . query ( `USE TestSuite` )
32- await pool . query ( 'DROP TABLE IF EXISTS [dbo].[Users]' )
33- await pool . close ( )
34- app . close ( )
35- } )
3630
37- test ( 'MSSQL plugin is loaded' , async ( ) => {
3831 app . register ( plugin , {
3932 user : 'sa' ,
4033 password : 'S3cretP4ssw0rd!' ,
@@ -67,27 +60,37 @@ describe('fastify-mssql', () => {
6760 return { error : err . message }
6861 }
6962 } )
63+ } )
7064
71- {
65+ after ( async ( ) => {
66+ const pool = await getPool ( )
67+ await pool . query ( `USE TestSuite` )
68+ await pool . query ( 'DROP TABLE IF EXISTS [dbo].[Users]' )
69+ await pool . close ( )
70+ app . close ( )
71+ } )
72+
73+ describe ( 'MSSQL plugin is loaded' , ( ) => {
74+ test ( 'correctly return users' , async ( ) => {
7275 const response = await app . inject ( {
7376 method : 'GET' ,
7477 url : '/users'
7578 } )
7679 const body = JSON . parse ( response . body )
77- expect ( app . mssql . pool ) . not . toBe ( undefined )
78- expect ( response . statusCode ) . toBe ( 200 )
79- expect ( body . users . length ) . toBe ( 2 )
80- }
80+ assert . ok ( app . mssql . pool )
81+ assert . deepStrictEqual ( response . statusCode , 200 )
82+ assert . deepStrictEqual ( body . users . length , 2 )
83+ } )
8184
82- {
85+ test ( 'correctly return user' , async ( ) => {
8386 const response = await app . inject ( {
8487 method : 'GET' ,
8588 url : '/users/2'
8689 } )
87- expect ( response . statusCode ) . toBe ( 200 )
88- expect ( response . json ( ) ) . toEqual ( {
90+ assert . deepStrictEqual ( response . statusCode , 200 )
91+ assert . deepStrictEqual ( response . json ( ) , {
8992 user : [ { id : '2' , name : 'fizzbuzz' , email : 'fizzbuzz@gmail.com' } ]
9093 } )
91- }
94+ } )
9295 } )
9396} )
0 commit comments