1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { addProperty, deleteProperty } from "./resource-properties";
6 import { omit, isEqual } from "lodash";
8 describe("Resource properties lib", () => {
15 color: ['brown', 'black'],
20 it("should convert a single string value into a list when adding values", () => {
21 expect(isEqual(addProperty(properties, 'animal', 'cat'), {...properties, animal: ['dog', 'cat']})).to.equal(true);
24 it("should convert a 2 value list into a string when removing values", () => {
25 expect(isEqual(deleteProperty(properties, 'color', 'brown'), {...properties, color: 'black'})).to.equal(true);
28 it("shouldn't add duplicated key:value items", () => {
29 expect(isEqual(addProperty(properties, 'name', 'Toby'), properties)).to.equal(true);
32 it("should remove the key when deleting from a one value list", () => {
33 expect(isEqual(deleteProperty(properties, 'name', 'Toby'), omit(properties, 'name'))).to.equal(true);
36 it("should return the same when deleting non-existant value", () => {
37 expect(isEqual(deleteProperty(properties, 'animal', 'dolphin'), properties)).to.equal(true);
40 it("should return the same when deleting non-existant key", () => {
41 expect(isEqual(deleteProperty(properties, 'doesntexist', 'something'), properties)).to.equal(true);