Path: blob/main/components/dashboard/src/data/setup.test.ts
2500 views
/**1* Copyright (c) 2023 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { Organization } from "@gitpod/public-api/lib/gitpod/v1/organization_pb";7import { Timestamp } from "@bufbuild/protobuf";8import { hydrate, dehydrate } from "./setup";910test("set and get proto message", async () => {11const now = new Date();12const org = new Organization({13creationTime: Timestamp.fromDate(now),14id: "test-id",15name: "test-name",16slug: "test-slug",17});1819expect(rehydrate(org).creationTime!.toDate()).toStrictEqual(now);20expect(rehydrate([org])[0].creationTime!.toDate()).toStrictEqual(now);21expect(rehydrate({ foo: org }).foo.creationTime!.toDate()).toStrictEqual(now);22});2324test("set and get proto message that include | in the message value", async () => {25const now = new Date();26const org = new Organization({27creationTime: Timestamp.fromDate(now),28id: "test-id",29name: "test-name|more",30slug: "test-slug",31});3233expect(rehydrate(org).creationTime!.toDate()).toStrictEqual(now);34expect(rehydrate([org])[0].creationTime!.toDate()).toStrictEqual(now);35expect(rehydrate({ foo: org }).foo.creationTime!.toDate()).toStrictEqual(now);36expect(rehydrate(org).name).toStrictEqual("test-name|more");37});3839function rehydrate<T>(obj: T): T {40const dehydrated = dehydrate(obj);41const str = JSON.stringify(dehydrated);42const fromStorage = JSON.parse(str);43const hydrated = hydrate(fromStorage);44return hydrated;45}464748