2022-01-31 21:09:58 +00:00
|
|
|
// Copyright 2021-2022 Signal Messenger, LLC
|
2021-05-06 00:09:29 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { assert } from 'chai';
|
2022-01-31 21:09:58 +00:00
|
|
|
import { MINUTE } from '../../util/durations';
|
2021-05-06 00:09:29 +00:00
|
|
|
|
|
|
|
import { parseRetryAfter } from '../../util/parseRetryAfter';
|
|
|
|
|
|
|
|
describe('parseRetryAfter', () => {
|
2022-01-31 21:09:58 +00:00
|
|
|
it('should return 1 minute when passed non-strings', () => {
|
|
|
|
assert.equal(parseRetryAfter(undefined), MINUTE);
|
|
|
|
assert.equal(parseRetryAfter(1234), MINUTE);
|
2021-09-02 22:31:21 +00:00
|
|
|
});
|
|
|
|
|
2022-01-31 21:09:58 +00:00
|
|
|
it('should return 1 minute with invalid strings', () => {
|
|
|
|
assert.equal(parseRetryAfter('nope'), MINUTE);
|
|
|
|
assert.equal(parseRetryAfter('1ff'), MINUTE);
|
2021-05-06 00:09:29 +00:00
|
|
|
});
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|