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';6import {requirePallets, Pallets} from '../deprecated-helpers/helpers';78describe('integration test: add Theme to Base', () => {9 let api: any;10 before(async function() {11 api = await getApiConnection();12 await requirePallets(this, [Pallets.RmrkEquip]);13 });1415 const alice = '//Alice';16 const bob = '//Bob';1718 it('add default theme', async () => {19 const baseId = await createBase(api, alice, 'default-themed-base', 'DTBase', []);20 await addTheme(api, alice, baseId, {21 name: 'default',22 properties: [23 {24 key: 'some-key',25 value: 'some-key-value',26 },27 {28 key: 'another-key',29 value: 'another-key-value',30 },31 ],32 });33 });3435 it('add default theme and a custom one', async () => {36 const baseId = await createBase(api, alice, '2-themed-base', '2TBase', []);37 await addTheme(api, alice, baseId, {38 name: 'default',39 properties: [40 {41 key: 'default-key',42 value: 'default-key-value',43 },44 ],45 });46 await addTheme(api, alice, baseId, {47 name: 'custom-theme',48 properties: [49 {50 key: 'custom-key-0',51 value: 'custom-key-value-0',52 },53 {54 key: 'custom-key-1',55 value: 'custom-key-value-1',56 },57 ],58 });59 });6061 it('fetch filtered theme keys', async () => {62 const baseId = await createBase(api, alice, '2-themed-base', '2TBase', []);63 await addTheme(api, alice, baseId, {64 name: 'default',65 properties: [66 {67 key: 'first-key',68 value: 'first-key-value',69 },70 {71 key: 'second-key',72 value: 'second-key-value',73 },74 ],75 }, ['second-key']);76 });7778 it('fetch theme names', async() => {79 const baseId = await createBase(api, alice, '3-themed-base', '3TBase', []);80 const names = [81 'default',82 'first-theme',83 'second-theme',84 ];8586 for (let i = 0; i < names.length; i++) {87 await addTheme(api, alice, baseId, {name: names[i], properties: [{key: 'dummy', value: 'dummy'}]});88 }8990 const fetchedNames = await getThemeNames(api, baseId);9192 for (let i = 0; i < names.length; i++) {93 const isFound = fetchedNames.find((name) => name === names[i]) !== undefined;9495 expect(isFound, 'Error: invalid theme names').to.be.true;96 }97 });9899 it('[negative] unable to add theme to non-existing base', async () => {100 const maxBaseId = 0xFFFFFFFF;101 const tx = addTheme(api, alice, maxBaseId, {102 name: 'default',103 properties: [],104 });105106 await expectTxFailure(/rmrkEquip\.BaseDoesntExist/, tx);107 });108109 it('[negative] unable to add custom theme if no default theme', async () => {110 const baseId = await createBase(api, alice, 'no-default-themed-base', 'NDTBase', []);111 const tx = addTheme(api, alice, baseId, {112 name: 'custom-theme',113 properties: [],114 });115116 await expectTxFailure(/rmrkEquip\.NeedsDefaultThemeFirst/, tx);117 });118119 it('[negative] unable to add theme by a not-an-owner', async () => {120 const baseId = await createBase(api, alice, 'no-default-themed-base', 'NDTBase', []);121 const tx = addTheme(api, bob, baseId, {122 name: 'default',123 properties: [],124 });125126 await expectTxFailure(/rmrkEquip\.PermissionError/, tx);127 });128129 after(() => { api.disconnect(); });130});