Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
adding test for RStudio auth URL
Browse files Browse the repository at this point in the history
  • Loading branch information
SanketD92 committed Sep 11, 2020
1 parent cdebe7e commit f8fde57
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,20 @@ const EnvironmentSCServiceMock = require('../environment-sc-service');
jest.mock('../environment-sc-keypair-service');
const EnvironmentScKeyPairServiceMock = require('../environment-sc-keypair-service');

jest.mock('request-promise-native', () => jest.fn(() => 'keyExponent:keyModulus'));
jest.mock('querystring', () => ({
encode: jest.fn(() => 'SampleEncodedParams'),
}));
jest.mock('@aws-ee/base-services/lib/helpers/rstudio-encryptor', () => ({
encrypt: jest.fn(() => 'SampleEncryptedKey'), // This will be used as sample sign-in params for RStudio URL
}));

const EnvironmentScConnectionService = require('../environment-sc-connection-service');

describe('EnvironmentScConnectionService', () => {
let service = null;
let envDnsService = null;

beforeEach(async () => {
const container = new ServicesContainer();
container.register('jsonSchemaValidationService', new JsonSchemaValidationService());
Expand All @@ -66,6 +76,8 @@ describe('EnvironmentScConnectionService', () => {

// Get instance of the service we are testing
service = await container.find('environmentScConnectionService');

envDnsService = await container.find('environmentDnsService');
});

describe('create connection', () => {
Expand Down Expand Up @@ -106,5 +118,19 @@ describe('EnvironmentScConnectionService', () => {
// CHECK
expect(service.getRStudioUrl).not.toHaveBeenCalled();
});

it('should get RStudio auth URL correctly', async () => {
// BUILD
const id = 'exampleId';
const connection = { instanceId: 'RStudioInstanceId' };
envDnsService.getHostname = jest.fn(() => `rstudio-${id}.example.com`);
service.mustFindConnection = jest.fn(() => connection);

// OPERATE
const authUrl = await service.getRStudioUrl(id, connection);

// CHECK
expect(authUrl).toEqual(`https://rstudio-${id}.example.com/auth-do-sign-in?SampleEncodedParams`);
});
});
});

0 comments on commit f8fde57

Please sign in to comment.