From 7456e254f0c6faec3c68015728bc88def413a0bc Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Wed, 25 Sep 2024 17:24:50 +0530 Subject: [PATCH] Fixed base64Encode and base64Decode usage across tests --- tests/ably/ably-user-rest-publishing.test.ts | 6 +++--- tests/ably/setup/mock-auth-server.ts | 4 ++-- tests/ably/setup/sandbox.ts | 4 ++-- tests/ably/setup/utils.ts | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/ably/ably-user-rest-publishing.test.ts b/tests/ably/ably-user-rest-publishing.test.ts index d6cf91b3..b5349d69 100644 --- a/tests/ably/ably-user-rest-publishing.test.ts +++ b/tests/ably/ably-user-rest-publishing.test.ts @@ -4,7 +4,7 @@ import { MockAuthServer } from './setup/mock-auth-server'; import { AblyChannel, AblyPrivateChannel } from '../../src/channel'; import * as Ably from 'ably'; import waitForExpect from 'wait-for-expect'; -import { toText } from '../../src/channel/ably/utils'; +import { fromBase64UrlEncoded } from '../../src/channel/ably/utils'; jest.setTimeout(30000); describe('AblyUserRestPublishing', () => { @@ -78,7 +78,7 @@ describe('AblyUserRestPublishing', () => { test('Guest user return socketId as base64 encoded connectionkey and null clientId', async () => { await getGuestUserChannel("dummyChannel"); const guestUser = echoInstanes[0]; - const socketIdObj = JSON.parse(toText(guestUser.socketId())); + const socketIdObj = JSON.parse(fromBase64UrlEncoded(guestUser.socketId())); const expectedConnectionKey = guestUser.connector.ably.connection.key; @@ -123,7 +123,7 @@ describe('AblyUserRestPublishing', () => { test('Logged in user return socketId as base64 encoded connectionkey and clientId', async () => { await getLoggedInUserChannel("dummyChannel"); const loggedInUser = echoInstanes[0]; - const socketIdObj = JSON.parse(toText(loggedInUser.socketId())); + const socketIdObj = JSON.parse(fromBase64UrlEncoded(loggedInUser.socketId())); const expectedConnectionKey = loggedInUser.connector.ably.connection.key; diff --git a/tests/ably/setup/mock-auth-server.ts b/tests/ably/setup/mock-auth-server.ts index c2f806b0..940a8589 100644 --- a/tests/ably/setup/mock-auth-server.ts +++ b/tests/ably/setup/mock-auth-server.ts @@ -1,4 +1,4 @@ -import { isNullOrUndefinedOrEmpty, parseJwt, toBase64, toText } from '../../../src/channel/ably/utils'; +import { isNullOrUndefinedOrEmpty, parseJwt, fromBase64UrlEncoded } from '../../../src/channel/ably/utils'; import * as Ably from 'ably/promises'; import * as jwt from 'jsonwebtoken'; @@ -40,7 +40,7 @@ export class MockAuthServer { broadcastToOthers = async (socketId: string, {channelName, eventName, payload}) => { let protoMsg = {name: eventName, data: payload}; if (!isNullOrUndefinedOrEmpty(socketId)) { - const socketIdObj = JSON.parse(toText(socketId)); + const socketIdObj = JSON.parse(fromBase64UrlEncoded(socketId)); protoMsg = {...protoMsg, ...socketIdObj} } await this.ablyClient.channels.get(channelName).publish(protoMsg); diff --git a/tests/ably/setup/sandbox.ts b/tests/ably/setup/sandbox.ts index a6884d9a..de9be9a3 100644 --- a/tests/ably/setup/sandbox.ts +++ b/tests/ably/setup/sandbox.ts @@ -1,4 +1,4 @@ -import { httpDeleteAsync, httpPostAsync, toBase64 } from './utils'; +import { httpDeleteAsync, httpPostAsync, toBase64UrlEncoded } from './utils'; let sandboxUrl = 'https://sandbox-rest.ably.io/apps'; @@ -16,7 +16,7 @@ const creatNewApp = async () => { const deleteApp = async (app) => { let authKey = app.keys[0].keyStr; - const headers = { Authorization: 'Basic ' + toBase64(authKey) }; + const headers = { Authorization: 'Basic ' + toBase64UrlEncoded(authKey) }; return await httpDeleteAsync(`${sandboxUrl}/${app.appId}`, headers); }; diff --git a/tests/ably/setup/utils.ts b/tests/ably/setup/utils.ts index 5d9a964c..9929bc0f 100644 --- a/tests/ably/setup/utils.ts +++ b/tests/ably/setup/utils.ts @@ -1,5 +1,5 @@ import { httpRequestAsync} from '../../../src/channel/ably/utils'; -export { toBase64 } from '../../../src/channel/ably/utils'; +export { toBase64UrlEncoded } from '../../../src/channel/ably/utils'; const safeAssert = (assertions: Function, done: Function, finalAssertion = false) => { try {