2021-05-06 00:09:29 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { assert } from 'chai';
|
|
|
|
|
|
|
|
import { parseRetryAfter } from '../../util/parseRetryAfter';
|
|
|
|
|
|
|
|
describe('parseRetryAfter', () => {
|
2021-09-02 22:31:21 +00:00
|
|
|
it('should return 1 second when passed non-strings', () => {
|
|
|
|
assert.equal(parseRetryAfter(undefined), 1000);
|
|
|
|
assert.equal(parseRetryAfter(1234), 1000);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return 1 second with invalid strings', () => {
|
2021-05-06 00:09:29 +00:00
|
|
|
assert.equal(parseRetryAfter('nope'), 1000);
|
|
|
|
assert.equal(parseRetryAfter('1ff'), 1000);
|
|
|
|
});
|
|
|
|
|
2021-09-02 22:31:21 +00:00
|
|
|
it('should return milliseconds on valid input', () => {
|
2021-05-06 00:09:29 +00:00
|
|
|
assert.equal(parseRetryAfter('100'), 100000);
|
|
|
|
});
|
|
|
|
|
2021-09-02 22:31:21 +00:00
|
|
|
it('should return 1 second at minimum', () => {
|
2021-05-06 00:09:29 +00:00
|
|
|
assert.equal(parseRetryAfter('0'), 1000);
|
|
|
|
assert.equal(parseRetryAfter('-1'), 1000);
|
|
|
|
});
|
|
|
|
});
|