Use assert
in normalizeUuid
This commit is contained in:
parent
9db19283ac
commit
c9b1ce6655
2 changed files with 12 additions and 5 deletions
|
@ -12,4 +12,11 @@ describe('normalizeUuid', () => {
|
||||||
assert.strictEqual(normalizeUuid(uuid, 'context 1'), uuid);
|
assert.strictEqual(normalizeUuid(uuid, 'context 1'), uuid);
|
||||||
assert.strictEqual(normalizeUuid(uuid.toUpperCase(), 'context 2'), uuid);
|
assert.strictEqual(normalizeUuid(uuid.toUpperCase(), 'context 2'), uuid);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("throws if passed a string that's not a UUID", () => {
|
||||||
|
assert.throws(
|
||||||
|
() => normalizeUuid('not-uuid-at-all', 'context 3'),
|
||||||
|
'Normalizing invalid uuid: not-uuid-at-all in context "context 3"'
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
// Copyright 2021 Signal Messenger, LLC
|
// Copyright 2021 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
import { assert } from './assert';
|
||||||
import { isValidGuid } from './isValidGuid';
|
import { isValidGuid } from './isValidGuid';
|
||||||
|
|
||||||
export function normalizeUuid(uuid: string, context: string): string {
|
export function normalizeUuid(uuid: string, context: string): string {
|
||||||
if (!isValidGuid(uuid)) {
|
assert(
|
||||||
window.log.warn(
|
isValidGuid(uuid),
|
||||||
`Normalizing invalid uuid: ${uuid} in context "${context}"`
|
`Normalizing invalid uuid: ${uuid} in context "${context}"`
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
return uuid.toLowerCase();
|
return uuid.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue