From 558afedfb6190aa6fcb2ac362a19b75cd76fa0d3 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Sat, 21 Sep 2024 18:44:09 +0200 Subject: [PATCH] code cleanup: use URLSearchParams instead of querystring --- test/Authentication.test.ts | 8 +++----- test/AuthenticationApprovalMode.test.ts | 7 +++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/test/Authentication.test.ts b/test/Authentication.test.ts index 2816f0e..885ad71 100644 --- a/test/Authentication.test.ts +++ b/test/Authentication.test.ts @@ -1,4 +1,3 @@ -import * as querystring from "querystring"; import supertest from "supertest"; import User from "../src/auth/models/User.js"; @@ -142,7 +141,7 @@ describe('Register with email (magic_link)', () => { const cookies = res.get('Set-Cookie') || []; const csrf = res.text; - await agent.post('/auth/register?' + querystring.stringify({redirect_uri: '/redirect-uri'})) + await agent.post('/auth/register?' + new URLSearchParams({redirect_uri: '/redirect-uri'}).toString()) .set('Cookie', cookies) .send({ csrf: csrf, @@ -303,7 +302,7 @@ describe('Authenticate with username and password (password)', () => { expect(res.body.messages?.password?.name).toStrictEqual('InvalidFormatValidationError'); // Authenticate - await agent.post('/auth/login?' + querystring.stringify({redirect_uri: '/redirect-uri'})) + await agent.post('/auth/login?' + new URLSearchParams({redirect_uri: '/redirect-uri'}).toString()) .set('Cookie', cookies) .send({ csrf: csrf, @@ -447,8 +446,7 @@ describe('Authenticate with email (magic_link)', () => { await agent.get('/is-auth').set('Cookie', cookies).expect(401); // Authenticate - // TODO deprecated querystring => URLSearchParams - await agent.post('/auth/login?' + querystring.stringify({redirect_uri: '/redirect-uri'})) + await agent.post('/auth/login?' + new URLSearchParams({redirect_uri: '/redirect-uri'}).toString()) .set('Cookie', cookies) .send({ csrf: csrf, diff --git a/test/AuthenticationApprovalMode.test.ts b/test/AuthenticationApprovalMode.test.ts index c6dd517..7f7bba4 100644 --- a/test/AuthenticationApprovalMode.test.ts +++ b/test/AuthenticationApprovalMode.test.ts @@ -1,4 +1,3 @@ -import querystring from "querystring"; import supertest from "supertest"; import User from "../src/auth/models/User.js"; @@ -66,7 +65,7 @@ describe('Register with email (magic_link)', () => { const cookies = res.get('Set-Cookie') || []; const csrf = res.text; - await agent.post('/auth/register?' + querystring.stringify({redirect_uri: '/redirect-uri'})) + await agent.post('/auth/register?' + new URLSearchParams({redirect_uri: '/redirect-uri'}).toString()) .set('Cookie', cookies) .send({ csrf: csrf, @@ -113,7 +112,7 @@ describe('Authenticate with username and password (password)', () => { await agent.get('/is-auth').set('Cookie', cookies).expect(401); // Authenticate - await agent.post('/auth/login?' + querystring.stringify({redirect_uri: '/redirect-uri'})) + await agent.post('/auth/login?' + new URLSearchParams({redirect_uri: '/redirect-uri'}).toString()) .set('Cookie', cookies) .send({ csrf: csrf, @@ -141,7 +140,7 @@ describe('Authenticate with email (magic_link)', () => { await agent.get('/is-auth').set('Cookie', cookies).expect(401); // Authenticate - await agent.post('/auth/login?' + querystring.stringify({redirect_uri: '/redirect-uri'})) + await agent.post('/auth/login?' + new URLSearchParams({redirect_uri: '/redirect-uri'}).toString()) .accept('json') .set('Cookie', cookies) .send({