2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2021 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
|
|
|
|
2022-04-25 23:05:23 +00:00
|
|
|
import { parseRetryAfterWithDefault } from '../../util/parseRetryAfter';
|
2021-05-06 00:09:29 +00:00
|
|
|
|
|
|
|
describe('parseRetryAfter', () => {
|
2022-01-31 21:09:58 +00:00
|
|
|
it('should return 1 minute when passed non-strings', () => {
|
2022-04-25 23:05:23 +00:00
|
|
|
assert.equal(parseRetryAfterWithDefault(undefined), MINUTE);
|
|
|
|
assert.equal(parseRetryAfterWithDefault(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', () => {
|
2022-04-25 23:05:23 +00:00
|
|
|
assert.equal(parseRetryAfterWithDefault('nope'), MINUTE);
|
|
|
|
assert.equal(parseRetryAfterWithDefault('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', () => {
|
2022-04-25 23:05:23 +00:00
|
|
|
assert.equal(parseRetryAfterWithDefault('100'), 100000);
|
2021-05-06 00:09:29 +00:00
|
|
|
});
|
|
|
|
|
2021-09-02 22:31:21 +00:00
|
|
|
it('should return 1 second at minimum', () => {
|
2022-04-25 23:05:23 +00:00
|
|
|
assert.equal(parseRetryAfterWithDefault('0'), 1000);
|
|
|
|
assert.equal(parseRetryAfterWithDefault('-1'), 1000);
|
2021-05-06 00:09:29 +00:00
|
|
|
});
|
|
|
|
});
|