Fix styling
This commit is contained in:
1 parent
0996c5fc27
commit
49c1633f52
6 files changed
+58
-84
No files matched your search
+22
-22
@@ -14,33 +14,33 @@ it('can sort query parameters in ascending ASCII order', function () {
|
||||
$parameters = [
|
||||
'uid' => '200',
|
||||
'id' => '1',
|
||||
'name' => 'test'
|
||||
'name' => 'test',
|
||||
];
|
||||
|
||||
|
||||
$sorted = Header::sortQueryParameters($parameters);
|
||||
|
||||
|
||||
expect(array_keys($sorted))->toBe(['id', 'name', 'uid']);
|
||||
expect($sorted)->toBe([
|
||||
'id' => '1',
|
||||
'name' => 'test',
|
||||
'uid' => '200'
|
||||
'uid' => '200',
|
||||
]);
|
||||
});
|
||||
|
||||
it('can digest query parameters to string format', function () {
|
||||
$parameters = [
|
||||
'id' => '1',
|
||||
'uid' => '200'
|
||||
'uid' => '200',
|
||||
];
|
||||
|
||||
|
||||
$result = Header::digestQueryParameters($parameters);
|
||||
|
||||
|
||||
expect($result)->toBe('id1uid200');
|
||||
});
|
||||
|
||||
it('can generate a valid nonce', function () {
|
||||
$nonce = Header::generateNonce();
|
||||
|
||||
|
||||
expect($nonce)
|
||||
->toBeString()
|
||||
->toHaveLength(32)
|
||||
@@ -49,7 +49,7 @@ it('can generate a valid nonce', function () {
|
||||
|
||||
it('can generate timestamp in milliseconds', function () {
|
||||
$timestamp = Header::generateTimestamp();
|
||||
|
||||
|
||||
expect($timestamp)
|
||||
->toBeString()
|
||||
->toMatch('/^\d{13}$/'); // 13 digits for milliseconds
|
||||
@@ -60,9 +60,9 @@ it('can generate signature according to Bitunix documentation', function () {
|
||||
$timestamp = '20241120123045';
|
||||
$queryParams = ['id' => '1', 'uid' => '200'];
|
||||
$body = '{"uid":"2899","arr":[{"id":1,"name":"maple"},{"id":2,"name":"lily"}]}';
|
||||
|
||||
|
||||
$sign = Header::generateSignValue($queryParams, $body, $nonce, $timestamp);
|
||||
|
||||
|
||||
expect($sign)
|
||||
->toBeString()
|
||||
->toHaveLength(64) // SHA256 hex length
|
||||
@@ -72,9 +72,9 @@ it('can generate signature according to Bitunix documentation', function () {
|
||||
it('can generate complete headers for authenticated requests', function () {
|
||||
$queryParams = ['symbol' => 'BTCUSDT'];
|
||||
$body = '{"symbol":"BTCUSDT","marginCoin":"USDT","leverage":12}';
|
||||
|
||||
|
||||
$headers = Header::generateHeaders($queryParams, $body);
|
||||
|
||||
|
||||
expect($headers)
|
||||
->toHaveKeys(['api-key', 'sign', 'nonce', 'timestamp', 'language', 'Content-Type'])
|
||||
->and($headers['api-key'])->toBe('test-api-key')
|
||||
@@ -90,23 +90,23 @@ it('throws exception when API credentials are missing', function () {
|
||||
'bitunix-api.api_key' => '',
|
||||
'bitunix-api.api_secret' => '',
|
||||
]);
|
||||
|
||||
expect(fn() => Header::generateSignValue([], '', 'nonce', 'timestamp'))
|
||||
|
||||
expect(fn () => Header::generateSignValue([], '', 'nonce', 'timestamp'))
|
||||
->toThrow(InvalidArgumentException::class, 'API key and secret must be configured');
|
||||
});
|
||||
|
||||
it('handles empty query parameters correctly', function () {
|
||||
$result = Header::digestQueryParameters([]);
|
||||
|
||||
|
||||
expect($result)->toBe('');
|
||||
});
|
||||
|
||||
it('handles empty body correctly', function () {
|
||||
$nonce = '123456';
|
||||
$timestamp = '20241120123045';
|
||||
|
||||
|
||||
$sign = Header::generateSignValue([], '', $nonce, $timestamp);
|
||||
|
||||
|
||||
expect($sign)
|
||||
->toBeString()
|
||||
->toHaveLength(64);
|
||||
@@ -117,19 +117,19 @@ it('generates consistent signature for same inputs', function () {
|
||||
$timestamp = '20241120123045';
|
||||
$queryParams = ['id' => '1'];
|
||||
$body = '{"test":"value"}';
|
||||
|
||||
|
||||
$sign1 = Header::generateSignValue($queryParams, $body, $nonce, $timestamp);
|
||||
$sign2 = Header::generateSignValue($queryParams, $body, $nonce, $timestamp);
|
||||
|
||||
|
||||
expect($sign1)->toBe($sign2);
|
||||
});
|
||||
|
||||
it('generates different signatures for different inputs', function () {
|
||||
$nonce = '123456';
|
||||
$timestamp = '20241120123045';
|
||||
|
||||
|
||||
$sign1 = Header::generateSignValue(['id' => '1'], '{"test":"value1"}', $nonce, $timestamp);
|
||||
$sign2 = Header::generateSignValue(['id' => '2'], '{"test":"value2"}', $nonce, $timestamp);
|
||||
|
||||
|
||||
expect($sign1)->not->toBe($sign2);
|
||||
});
|
||||
Reference in new issue
Block a user