Skip to content

Commit

Permalink
Fixed base64Encode and base64Decode usage across tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Sep 25, 2024
1 parent 0cfd258 commit 7456e25
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions tests/ably/ably-user-rest-publishing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions tests/ably/setup/mock-auth-server.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/ably/setup/sandbox.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { httpDeleteAsync, httpPostAsync, toBase64 } from './utils';
import { httpDeleteAsync, httpPostAsync, toBase64UrlEncoded } from './utils';

let sandboxUrl = 'https://sandbox-rest.ably.io/apps';

Expand All @@ -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);
};

Expand Down
2 changes: 1 addition & 1 deletion tests/ably/setup/utils.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit 7456e25

Please sign in to comment.