mirror of
https://github.com/bitwarden/browser
synced 2025-12-23 03:33:54 +00:00
[PM-16790] introduce extension service (#13590)
This commit is contained in:
27
libs/common/src/tools/state/classified-format.spec.ts
Normal file
27
libs/common/src/tools/state/classified-format.spec.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { isClassifiedFormat } from "./classified-format";
|
||||
|
||||
describe("isClassifiedFormat", () => {
|
||||
it("returns `false` when the argument is `null`", () => {
|
||||
expect(isClassifiedFormat(null)).toEqual(false);
|
||||
});
|
||||
|
||||
it.each([
|
||||
[{ id: true, secret: "" }],
|
||||
[{ secret: "", disclosed: {} }],
|
||||
[{ id: true, disclosed: {} }],
|
||||
])("returns `false` when the argument is missing a required member (=%p).", (value) => {
|
||||
expect(isClassifiedFormat(value)).toEqual(false);
|
||||
});
|
||||
|
||||
it("returns `false` when 'secret' is not a string", () => {
|
||||
expect(isClassifiedFormat({ id: true, secret: false, disclosed: {} })).toEqual(false);
|
||||
});
|
||||
|
||||
it("returns `false` when 'disclosed' is not an object", () => {
|
||||
expect(isClassifiedFormat({ id: true, secret: "", disclosed: false })).toEqual(false);
|
||||
});
|
||||
|
||||
it("returns `true` when the argument has a `secret`, `disclosed`, and `id`.", () => {
|
||||
expect(isClassifiedFormat({ id: true, secret: "", disclosed: {} })).toEqual(true);
|
||||
});
|
||||
});
|
||||
@@ -21,5 +21,12 @@ export type ClassifiedFormat<Id, Disclosed> = {
|
||||
export function isClassifiedFormat<Id, Disclosed>(
|
||||
value: any,
|
||||
): value is ClassifiedFormat<Id, Disclosed> {
|
||||
return "id" in value && "secret" in value && "disclosed" in value;
|
||||
return (
|
||||
!!value &&
|
||||
"id" in value &&
|
||||
"secret" in value &&
|
||||
"disclosed" in value &&
|
||||
typeof value.secret === "string" &&
|
||||
typeof value.disclosed === "object"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -523,6 +523,7 @@ export class UserStateSubject<
|
||||
|
||||
private onError(value: any) {
|
||||
if (!this.isDisposed) {
|
||||
this.log.debug(value, "forwarding error to subscribers");
|
||||
this.output.error(value);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user