mirror of
https://github.com/logto-io/logto.git
synced 2025-01-20 21:32:31 -05:00
6b322a537c
the initial commit to move all connector packages to the main repo.
62 lines
2.5 KiB
TypeScript
62 lines
2.5 KiB
TypeScript
import { methodForAccessToken } from './constant.js';
|
|
import {
|
|
mockedAlipayNativeConfigWithValidPrivateKey,
|
|
mockedAlipayNativePublicParameters,
|
|
} from './mock.js';
|
|
import { signingParameters } from './utils.js';
|
|
|
|
const { jest } = import.meta;
|
|
|
|
const listenJSONParse = jest.spyOn(JSON, 'parse');
|
|
const listenJSONStringify = jest.spyOn(JSON, 'stringify');
|
|
|
|
describe('signingParameters', () => {
|
|
afterEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
const testingParameters = {
|
|
...mockedAlipayNativePublicParameters,
|
|
...mockedAlipayNativeConfigWithValidPrivateKey,
|
|
method: methodForAccessToken,
|
|
code: '7ffeb112fbb6495c9e7dfb720380DD39',
|
|
};
|
|
|
|
it('should return exact signature with the given parameters (functionality check)', () => {
|
|
const decamelizedParameters = signingParameters(testingParameters);
|
|
expect(decamelizedParameters.sign).toBe(
|
|
'jqVzRnwdvBEIocvKGZlZ4X3CK0pEsm8HpRWL9FtGS+P8ZRehh+Wvb3lmXWf0fhTIHmcZahQMAnLFO3OmqcwlUrs4PuRgPVmLG6mK087tkw/GP18hlstnD1hN3DS98eZZQsn8psxdHQ1qtzuik1fM0hiZvR7d/Pr72yNhIzgzWa66wBXJGYc6cmSQzB7g5hFg7L/SC55Xk205tkXkenPO9ti2TY8+bWOEZ4hAteWGftwCROz+1ne3EVrt2e/LpQQvRmDPhMIRVEShmcGTNj0ovnjN2K4Uo/YB7+hPLJkrGpYBV4hDEV91KQ9RybmE927xgIzXl7xbiHvK+BayFGNzFA=='
|
|
);
|
|
});
|
|
|
|
it('should return exact signature with the given parameters (with empty property in testingParameters)', () => {
|
|
const decamelizedParameters = signingParameters({
|
|
...testingParameters,
|
|
emptyProperty: '',
|
|
});
|
|
expect(decamelizedParameters.sign).toBe(
|
|
'jqVzRnwdvBEIocvKGZlZ4X3CK0pEsm8HpRWL9FtGS+P8ZRehh+Wvb3lmXWf0fhTIHmcZahQMAnLFO3OmqcwlUrs4PuRgPVmLG6mK087tkw/GP18hlstnD1hN3DS98eZZQsn8psxdHQ1qtzuik1fM0hiZvR7d/Pr72yNhIzgzWa66wBXJGYc6cmSQzB7g5hFg7L/SC55Xk205tkXkenPO9ti2TY8+bWOEZ4hAteWGftwCROz+1ne3EVrt2e/LpQQvRmDPhMIRVEShmcGTNj0ovnjN2K4Uo/YB7+hPLJkrGpYBV4hDEV91KQ9RybmE927xgIzXl7xbiHvK+BayFGNzFA=='
|
|
);
|
|
});
|
|
|
|
it('should not call JSON.parse() when biz_content is empty', () => {
|
|
signingParameters(testingParameters);
|
|
expect(listenJSONParse).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should call JSON.parse() when biz_content is not empty', () => {
|
|
signingParameters({
|
|
...testingParameters,
|
|
biz_content: JSON.stringify({ AB: 'AB' }),
|
|
});
|
|
expect(listenJSONParse).toHaveBeenCalled();
|
|
});
|
|
|
|
it('should call JSON.stringify() when some value is object string', () => {
|
|
signingParameters({
|
|
...testingParameters,
|
|
testObject: JSON.stringify({ AB: 'AB' }),
|
|
});
|
|
expect(listenJSONStringify).toHaveBeenCalled();
|
|
});
|
|
});
|