component-dbs-core
Version:
DTO objects shared among device backend
206 lines • 10.9 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const uuid_1 = require("uuid");
const identityService_1 = require("./identityService");
const testing_1 = require("@nestjs/testing");
const config_1 = require("@nestjs/config");
const envService_1 = require("../../common_services/config/envService");
const auth0Service_1 = __importDefault(require("../../authzero/__mocks__/auth0Service"));
const deviceVerification_1 = require("../../devices/deviceVerification");
const deviceService_1 = require("../../devices/deviceService");
const deviceMetrics_1 = require("../../devices/deviceMetrics");
const signUpTestSuite_1 = require("./testcases/signUpTestSuite");
const loginTestSuite_1 = require("./testcases/loginTestSuite");
const checkTokenTestSuite_1 = require("./testcases/checkTokenTestSuite");
const forgotPwdTestSuite_1 = require("./testcases/forgotPwdTestSuite");
const changePwdTestSuite_1 = require("./testcases/changePwdTestSuite");
const common_1 = require("@nestjs/common");
const phoneRegisterTestSuite_1 = require("./testcases/phoneRegisterTestSuite");
const testCases_1 = require("./testcases/testCases");
const phoneVerifyTestSuite_1 = require("./testcases/phoneVerifyTestSuite");
const auth0Module_1 = require("../../authzero/auth0Module");
const verifyPinTestSuite_1 = require("./testcases/verifyPinTestSuite");
const setPinTestSuite_1 = require("./testcases/setPinTestSuite");
const ts_mockito_1 = require("ts-mockito");
const common_services_1 = require("../../common_services");
jest.mock('../../common_services/dynamodb/dynamodbService');
describe('Identity service test suite', () => {
let deviceService;
const mockAppSyncClient = ts_mockito_1.mock(common_services_1.AppSyncClient);
let underTest;
let app;
//TEST PARAMETERS
var testWithMockApi = true;
const signUpTests = new signUpTestSuite_1.SignUpTestSuite();
const loginTests = new loginTestSuite_1.LoginTestSuite();
const checkTokenTests = new checkTokenTestSuite_1.CheckTokenTestSuite();
const forgotPwdTests = new forgotPwdTestSuite_1.ForgotPwdTestSuite();
const changePwdTest = new changePwdTestSuite_1.ChangePwdTestSuite();
const phoneRegisterTests = new phoneRegisterTestSuite_1.PhoneRegisterTestSuite();
const phoneVerifyTests = new phoneVerifyTestSuite_1.PhoneVerifyTestSuite();
const setPinTests = new setPinTestSuite_1.SetPinTestSuite();
const verifyPinTests = new verifyPinTestSuite_1.VerifyPinTestSuite();
let allEnvs;
beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {
app = yield testing_1.Test.createTestingModule({
imports: [
config_1.ConfigModule.forRoot({
isGlobal: true,
}),
common_1.HttpModule,
auth0Module_1.Auth0Module,
],
providers: [
envService_1.EnvironmentService,
identityService_1.IdentityService,
deviceMetrics_1.DeviceMetrics,
deviceService_1.DeviceService,
deviceVerification_1.DeviceVerification,
{
provide: 'Auth0Service',
useClass: auth0Service_1.default,
},
{
provide: 'AppSyncClient',
useValue: ts_mockito_1.instance(mockAppSyncClient),
},
common_services_1.DynamodbService,
common_services_1.DynamodbUtils,
common_services_1.AppSyncUtils,
],
}).compile();
underTest = app.get(identityService_1.IdentityService);
deviceService = app.get(deviceService_1.DeviceService);
}));
afterAll(() => {
process.env = allEnvs;
});
test.each(checkTokenTests.params)('%o, %o', (testCase, expected) => __awaiter(void 0, void 0, void 0, function* () {
const testCaseParam = (yield checkTokenTests.getParameterForTestCase(testCase, deviceService, testWithMockApi));
try {
const result = yield underTest.checkAccessToken(testCaseParam);
expect(result).toMatchSnapshot(testCases_1.IdentityTestCase[testCase]);
}
catch (e) {
return expect(e).toMatchSnapshot(testCases_1.IdentityTestCase[testCase]);
}
}));
test.each(signUpTests.params)('%o, %o', (testCase, expected) => __awaiter(void 0, void 0, void 0, function* () {
const testCaseParam = (yield signUpTests.getParameterForTestCase(testCase, deviceService, testWithMockApi));
try {
//all positive tests goes here
const result = yield underTest.identitySignUp(testCaseParam);
return expect(result).toMatchSnapshot(testCases_1.IdentityTestCase[testCase]);
}
catch (e) {
//all negative tests goes here
return expect(e).toMatchSnapshot(testCases_1.IdentityTestCase[testCase]);
}
}));
test.each(loginTests.params)('%o, %o', (testCase, expected) => __awaiter(void 0, void 0, void 0, function* () {
const testCaseParam = (yield loginTests.getParameterForTestCase(testCase, deviceService, testWithMockApi));
try {
const result = yield underTest.identityLogin(testCaseParam);
expect(result).toMatchSnapshot(testCases_1.IdentityTestCase[testCase]);
}
catch (e) {
return expect(e).toMatchSnapshot(testCases_1.IdentityTestCase[testCase]);
}
}));
test.each(forgotPwdTests.params)('%o, %o', (testCase, expected) => __awaiter(void 0, void 0, void 0, function* () {
const testCaseParam = yield forgotPwdTests.getParameterForTestCase(testCase, testWithMockApi);
try {
const result = yield underTest.identityForgotPassword(testCaseParam);
expect(result).toMatchSnapshot(testCases_1.IdentityTestCase[testCase]);
}
catch (e) {
return expect(e).toMatchSnapshot(testCases_1.IdentityTestCase[testCase]);
}
}));
test.each(changePwdTest.params)('%o, %o', (testCase, expected) => __awaiter(void 0, void 0, void 0, function* () {
const testCaseParam = (yield changePwdTest.getParameterForTestCase(testCase, deviceService));
try {
const result = yield underTest.identityChangePassword(testCaseParam);
expect(result).toMatchSnapshot(testCases_1.IdentityTestCase[testCase]);
}
catch (e) {
expect(e).toMatchSnapshot(testCases_1.IdentityTestCase[testCase]);
}
}));
test.each(phoneRegisterTests.params)('%o, %o', (testCase, expected) => __awaiter(void 0, void 0, void 0, function* () {
const testCaseParam = yield phoneRegisterTests.getParameterForTestCase(testCase, deviceService);
try {
const result = yield underTest.identityPhoneRegister(testCaseParam);
return expect(result).toEqual(expect.objectContaining({
codeSent: true,
validUntil: expect.any(String),
}));
}
catch (e) {
return expect(e.message).toMatchSnapshot(testCases_1.IdentityTestCase[testCase]);
}
}));
test.each(phoneVerifyTests.params)('%o, %o', (testCase, expected) => __awaiter(void 0, void 0, void 0, function* () {
const testCaseParam = yield phoneVerifyTests.getParameterForTestCase(testCase);
try {
const result = yield underTest.identityPhoneVerify(testCaseParam);
return expect(result).toMatchSnapshot(testCases_1.IdentityTestCase[testCase]);
}
catch (e) {
return expect(e).toMatchSnapshot(testCases_1.IdentityTestCase[testCase]);
}
}));
test.each(setPinTests.params)('%o, %o', (testCase, expected) => __awaiter(void 0, void 0, void 0, function* () {
const testCaseParam = yield setPinTests.getParameterForTestCase(testCase, deviceService);
try {
const result = yield underTest.identitySetPin(testCaseParam);
expect(result).toMatchSnapshot(testCases_1.IdentityTestCase[testCase]);
}
catch (e) {
expect(e).toMatchSnapshot(testCases_1.IdentityTestCase[testCase]);
}
}));
test.each(verifyPinTests.params)('%o, %o', (testCase, expected) => __awaiter(void 0, void 0, void 0, function* () {
const testCaseParam = yield verifyPinTests.getParameterForTestCase(testCase, deviceService);
try {
const result = yield underTest.identityVerifyPin(testCaseParam);
expect(result).toMatchSnapshot(testCases_1.IdentityTestCase[testCase]);
}
catch (e) {
expect(e).toMatchSnapshot(testCases_1.IdentityTestCase[testCase]);
}
}));
test('should return ForcedLogoff response on initiateForcedLogoff', () => __awaiter(void 0, void 0, void 0, function* () {
const mutate = jest.fn();
ts_mockito_1.when(mockAppSyncClient.getAppSyncClient()).thenReturn(Promise.resolve({ mutate }));
yield underTest.initiateForcedLogoff('devuceUuid', 'reason');
expect(mutate).toBeCalledTimes(1);
}));
test('should return error on identityForcedLogoff with incorrect deviceUuid', () => __awaiter(void 0, void 0, void 0, function* () {
expect(underTest.identityForcedLogoff('devuceUuid', 'reason')).rejects.toMatchObject(new Error('An error happened during forced logoff'));
}));
test('should return sucess response on identityForcedLogoff', () => __awaiter(void 0, void 0, void 0, function* () {
const model = uuid_1.v4().slice(-16);
const serial = uuid_1.v4().slice(-16);
const deviceUuid = yield deviceService.getDeviceUuid({ model, serial });
yield deviceService.saveDeviceTokens(deviceUuid.id, 'access-token', 'refresh-token');
const res = yield underTest.identityForcedLogoff(deviceUuid.id, 'Test logoff');
expect(res).toMatchObject({
deviceUuid: deviceUuid.id,
reason: 'Test logoff',
});
}));
});
//# sourceMappingURL=identityService.spec.js.map