Skip to content

Commit b2a55f6

Browse files
committed
Refactor test
1 parent b9cab60 commit b2a55f6

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

src/__tests__/security/nexoSecurityManager.spec.ts

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import NexoSecurityManager from "../../security/nexoSecurityManager";
2121
import { EncryptionCredentialDetails } from "../../security/encryptionCredentialDetails";
22-
import { MessageHeader, SaleToPOISecuredMessage, MessageCategoryType, MessageClassType, MessageType } from "../../typings/cloudDevice/models";
22+
import { MessageHeader, SaleToPOISecuredMessage, MessageCategoryType, MessageClassType, MessageType, CloudDeviceApiRequest, PaymentRequest} from "../../typings/cloudDevice/models";
2323
import InvalidSecurityKeyException from "../../security/exception/invalidSecurityKeyException";
2424
import NexoCryptoException from "../../services/exception/nexoCryptoException";
2525

@@ -41,22 +41,43 @@ describe("NexoSecurityManager", (): void => {
4141
ServiceID: "001",
4242
};
4343

44-
const saleToPoiMessageJson = JSON.stringify({
45-
PaymentRequest: {
46-
SaleData: {
47-
SaleTransactionID: {
48-
TransactionID: "001",
49-
TimeStamp: "2025-01-01T00:00:00.000Z",
50-
},
44+
const paymentRequest: PaymentRequest = {
45+
PaymentTransaction: {
46+
AmountsReq: {
47+
Currency: "EUR",
48+
RequestedAmount: 1,
5149
},
5250
},
53-
});
51+
SaleData: {
52+
SaleTransactionID: {
53+
TimeStamp: "2025-09-11T08:51:30.698Z",
54+
TransactionID: "123456789",
55+
},
56+
SaleToAcquirerData: {
57+
applicationInfo: {
58+
merchantApplication: {
59+
version: "1",
60+
name: "test"
61+
}
62+
},
63+
}
64+
},
65+
};
66+
67+
const cloudDeviceApiRequest: CloudDeviceApiRequest = {
68+
SaleToPOIRequest: {
69+
MessageHeader: messageHeader,
70+
PaymentRequest: paymentRequest,
71+
},
72+
};
73+
74+
const payload: string = JSON.stringify(cloudDeviceApiRequest)
5475

5576
it("should encrypt and decrypt a message successfully", (): void => {
5677
// Encrypt
5778
const securedMessage: SaleToPOISecuredMessage = NexoSecurityManager.encrypt(
5879
messageHeader,
59-
saleToPoiMessageJson,
80+
payload,
6081
credentials,
6182
);
6283

@@ -74,7 +95,7 @@ describe("NexoSecurityManager", (): void => {
7495
// Decrypt
7596
const decryptedJson = NexoSecurityManager.decrypt(securedMessage, credentials);
7697

77-
expect(decryptedJson).toBe(saleToPoiMessageJson);
98+
expect(decryptedJson).toBe(payload);
7899
});
79100

80101
it("should throw InvalidSecurityKeyException on decrypt with invalid credentials", (): void => {
@@ -90,7 +111,7 @@ describe("NexoSecurityManager", (): void => {
90111

91112
const securedMessage: SaleToPOISecuredMessage = NexoSecurityManager.encrypt(
92113
messageHeader,
93-
saleToPoiMessageJson,
114+
payload,
94115
credentials,
95116
);
96117

@@ -106,7 +127,7 @@ describe("NexoSecurityManager", (): void => {
106127
it("should throw NexoCryptoException on decrypt with wrong HMAC", (): void => {
107128
const securedMessage: SaleToPOISecuredMessage = NexoSecurityManager.encrypt(
108129
messageHeader,
109-
saleToPoiMessageJson,
130+
payload,
110131
credentials,
111132
);
112133

@@ -126,7 +147,7 @@ describe("NexoSecurityManager", (): void => {
126147
it("should throw NexoCryptoException on decrypt with wrong passphrase", (): void => {
127148
const securedMessage: SaleToPOISecuredMessage = NexoSecurityManager.encrypt(
128149
messageHeader,
129-
saleToPoiMessageJson,
150+
payload,
130151
credentials,
131152
);
132153

@@ -137,6 +158,6 @@ describe("NexoSecurityManager", (): void => {
137158

138159
expect((): string => NexoSecurityManager.decrypt(securedMessage, wrongCredentials))
139160
.toThrow(NexoCryptoException);
140-
161+
141162
});
142163
});

0 commit comments

Comments
 (0)