git.delta.rocks / unique-network / refs/commits / 86d26e3a07ad

difftreelog

source

tests/src/rmrk/addTheme.test.ts4.0 KiBsourcehistory
1import { expect } from 'chai';2import { getApiConnection } from '../substrate/substrate-api';3import { createBase, addTheme } from "./util/tx";4import { expectTxFailure } from './util/helpers';5import { getThemeNames } from './util/fetch';67describe("integration test: add Theme to Base", () => {8    let api: any;9    before(async () => { api = await getApiConnection(); });1011    const alice = "//Alice";12    const bob = "//Bob";1314    it("add default theme", async () => {15        const baseId = await createBase(api, alice, "default-themed-base", "DTBase", []);16        await addTheme(api, alice, baseId, {17            name: "default",18            properties: [19                {20                    key: "some-key",21                    value: "some-key-value"22                },23                {24                    key: "another-key",25                    value: "another-key-value"26                }27            ]28        });29    });3031    it("add default theme and a custom one", async () => {32        const baseId = await createBase(api, alice, "2-themed-base", "2TBase", []);33        await addTheme(api, alice, baseId, {34            name: "default",35            properties: [36                {37                    key: "default-key",38                    value: "default-key-value"39                }40            ]41        });42        await addTheme(api, alice, baseId, {43            name: "custom-theme",44            properties: [45                {46                    key: "custom-key-0",47                    value: "custom-key-value-0"48                },49                {50                    key: "custom-key-1",51                    value: "custom-key-value-1"52                }53            ]54        })55    });5657    it("fetch filtered theme keys", async () => {58        const baseId = await createBase(api, alice, "2-themed-base", "2TBase", []);59        await addTheme(api, alice, baseId, {60            name: "default",61            properties: [62                {63                    key: "first-key",64                    value: "first-key-value"65                },66                {67                    key: "second-key",68                    value: "second-key-value"69                }70            ]71        }, ["second-key"]);72    });7374    it("fetch theme names", async() => {75        const baseId = await createBase(api, alice, "3-themed-base", "3TBase", []);76        const names = [77            "default",78            "first-theme",79            "second-theme"80        ];8182        for (var i = 0; i < names.length; i++) {83            await addTheme(api, alice, baseId, { name: names[i], properties: [{ key: 'dummy', value: 'dummy' }] });84        }8586        const fetchedNames = await getThemeNames(api, baseId);8788        for (var i = 0; i < names.length; i++) {89            const isFound = fetchedNames.find(90                (name) => name === names[i]91            ) !== undefined;9293            expect(isFound, "Error: invalid theme names").to.be.true;94        }95    });9697    it("[negative] unable to add theme to non-existing base", async () => {98        const maxBaseId = 0xFFFFFFFF;99        const tx = addTheme(api, alice, maxBaseId, {100            name: "default",101            properties: []102        });103104        await expectTxFailure(/rmrkEquip\.BaseDoesntExist/, tx);105    });106107    it("[negative] unable to add custom theme if no default theme", async () => {108        const baseId = await createBase(api, alice, "no-default-themed-base", "NDTBase", []);109        const tx = addTheme(api, alice, baseId, {110            name: "custom-theme",111            properties: []112        });113114        await expectTxFailure(/rmrkEquip\.NeedsDefaultThemeFirst/, tx);115    });116117    it("[negative] unable to add theme by a not-an-owner", async () => {118        const baseId = await createBase(api, alice, "no-default-themed-base", "NDTBase", []);119        const tx = addTheme(api, bob, baseId, {120            name: "default",121            properties: []122        });123124        await expectTxFailure(/rmrkEquip\.PermissionError/, tx);125    });126127    after(() => { api.disconnect(); });128});