From 41658ace1742a1bc6af651962a6207f7de8ecd92 Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Mon, 3 Feb 2020 18:39:51 -0300 Subject: [PATCH] 15781: Adds tests for resource properties util functions. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- src/lib/resource-properties.test.ts | 59 +++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/lib/resource-properties.test.ts diff --git a/src/lib/resource-properties.test.ts b/src/lib/resource-properties.test.ts new file mode 100644 index 00000000..c70b2315 --- /dev/null +++ b/src/lib/resource-properties.test.ts @@ -0,0 +1,59 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import * as _ from "./resource-properties"; +import { omit } from "lodash"; + +describe("Resource properties lib", () => { + + let properties: any; + + beforeEach(() => { + properties = { + animal: 'dog', + color: ['brown', 'black'], + name: ['Toby'] + } + }) + + it("should convert a single string value into a list when adding values", () => { + expect( + _.addProperty(properties, 'animal', 'cat') + ).toEqual({ + ...properties, animal: ['dog', 'cat'] + }); + }); + + it("should convert a 2 value list into a string when removing values", () => { + expect( + _.deleteProperty(properties, 'color', 'brown') + ).toEqual({ + ...properties, color: 'black' + }); + }); + + it("shouldn't add duplicated key:value items", () => { + expect( + _.addProperty(properties, 'animal', 'dog') + ).toEqual(properties); + }); + + it("should remove the key when deleting from a one value list", () => { + expect( + _.deleteProperty(properties, 'name', 'Toby') + ).toEqual(omit(properties, 'name')); + }); + + it("should return the same when deleting non-existant value", () => { + expect( + _.deleteProperty(properties, 'animal', 'dolphin') + ).toEqual(properties); + }); + + it("should return the same when deleting non-existant key", () => { + expect( + _.deleteProperty(properties, 'doesntexist', 'something') + ).toEqual(properties); + }); +}); \ No newline at end of file -- 2.30.2