component-dbs-core
Version:
DTO objects shared among device backend
106 lines • 6.05 kB
JavaScript
;
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const devices_1 = require("../devices");
const transactionService_1 = require("../transactions/transactionService");
const lambdaTransaction_1 = require("./lambdaTransaction");
jest.mock('../devices/deviceService');
jest.mock('../devices/deviceVerification');
jest.mock('../transactions/transactionService');
describe('transaction lambda test suite', () => {
beforeEach(() => {
transactionService_1.TransactionService.getTransactions.mockReset();
transactionService_1.TransactionService.getTransaction.mockReset();
devices_1.DeviceVerification.mockCheckAccessToken.mockReset();
devices_1.DeviceVerification.accessTokenValid = true;
transactionService_1.TransactionService.onTransactionUpdate.mockReset();
});
it('should be able to handle getTransaction request', (done) => __awaiter(void 0, void 0, void 0, function* () {
lambdaTransaction_1.getTransactionHandler({ request: { headers: { authorization: 'token001' } }, args: {} }, {}, (error, response) => {
expect(transactionService_1.TransactionService.getTransaction).toHaveBeenCalledTimes(1);
expect(devices_1.DeviceVerification.mockCheckAccessToken).toHaveBeenCalledTimes(1);
done();
});
}));
it('should throw error if access token is invalid', (done) => __awaiter(void 0, void 0, void 0, function* () {
devices_1.DeviceVerification.accessTokenValid = false;
lambdaTransaction_1.getTransactionHandler({ request: { headers: { authorization: 'token001' } }, args: {} }, {}, (error, response) => {
expect(error).not.toBeNull();
expect(devices_1.DeviceVerification.mockCheckAccessToken).toHaveBeenCalledTimes(1);
expect(transactionService_1.TransactionService.getTransaction).toHaveBeenCalledTimes(0);
done();
});
}));
it('should report error if access token is not present when get transactions', (done) => __awaiter(void 0, void 0, void 0, function* () {
lambdaTransaction_1.getTransactionsHandler({ args: {}, request: {} }, {}, (error, response) => {
expect(error).not.toBe(undefined);
expect(transactionService_1.TransactionService.getTransactions).toHaveBeenCalledTimes(0);
done();
});
}));
it('should be able to call get transactions', (done) => __awaiter(void 0, void 0, void 0, function* () {
lambdaTransaction_1.getTransactionsHandler({ request: { headers: { authorization: 'token001' } } }, {}, (_, response) => {
expect(transactionService_1.TransactionService.getTransactions).toHaveBeenCalledTimes(1);
done();
});
}));
it('should handle transaction request', (done) => __awaiter(void 0, void 0, void 0, function* () {
lambdaTransaction_1.requestTransactionHandler({
args: { transaction: { id: '123' } },
request: { headers: { authorization: 'token001' } },
}, {}, (error, response) => {
expect(error).toBeNull();
expect(transactionService_1.TransactionService.requestTransaction).toHaveBeenCalledTimes(1);
done();
});
}));
it('should handle subscribe transaction response', (done) => __awaiter(void 0, void 0, void 0, function* () {
lambdaTransaction_1.subscribeTransactionResponseHandler({ args: { id: '123' } }, {}, (error, response) => {
expect(transactionService_1.TransactionService.subscribeTransactionResponse).toHaveBeenCalledTimes(1);
done();
});
}));
it('should be able to handle get transaction by card request', (done) => __awaiter(void 0, void 0, void 0, function* () {
lambdaTransaction_1.getTransactionByCard({
args: { id: '123' },
request: { headers: { authorization: 'token001' } },
}, {}, () => {
expect(transactionService_1.TransactionService.getTransactions).toHaveBeenCalledTimes(1);
done();
});
}));
it('should be able to handle onTransactionUpdate request', (done) => __awaiter(void 0, void 0, void 0, function* () {
devices_1.DeviceService.mockGetDeviceStatus = jest
.fn()
.mockResolvedValue("ACTIVE" /* ACTIVE */);
lambdaTransaction_1.onTransactionUpdateHandler({
args: { id: '123' },
request: { headers: { authorization: 'token001' } },
}, {}, () => {
expect(transactionService_1.TransactionService.onTransactionUpdate).toHaveBeenCalledTimes(1);
done();
});
}));
it('should throw error if device status is not active onTransactionUpdate request', (done) => __awaiter(void 0, void 0, void 0, function* () {
devices_1.DeviceService.mockGetDeviceStatus = jest
.fn()
.mockResolvedValue("INACTIVE" /* INACTIVE */);
lambdaTransaction_1.onTransactionUpdateHandler({
args: { id: '123' },
request: { headers: { authorization: 'token001' } },
}, {}, (error) => {
expect(error).not.toBeNull();
expect(transactionService_1.TransactionService.onTransactionUpdate).toHaveBeenCalledTimes(0);
done();
});
}));
});
//# sourceMappingURL=lambdaTransaction.spec.js.map