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 (let 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 (let i = 0; i < names.length; i++) {89 const isFound = fetchedNames.find((name) => name === names[i]) !== undefined;9091 expect(isFound, 'Error: invalid theme names').to.be.true;92 }93 });9495 it('[negative] unable to add theme to non-existing base', async () => {96 const maxBaseId = 0xFFFFFFFF;97 const tx = addTheme(api, alice, maxBaseId, {98 name: 'default',99 properties: [],100 });101102 await expectTxFailure(/rmrkEquip\.BaseDoesntExist/, tx);103 });104105 it('[negative] unable to add custom theme if no default theme', async () => {106 const baseId = await createBase(api, alice, 'no-default-themed-base', 'NDTBase', []);107 const tx = addTheme(api, alice, baseId, {108 name: 'custom-theme',109 properties: [],110 });111112 await expectTxFailure(/rmrkEquip\.NeedsDefaultThemeFirst/, tx);113 });114115 it('[negative] unable to add theme by a not-an-owner', async () => {116 const baseId = await createBase(api, alice, 'no-default-themed-base', 'NDTBase', []);117 const tx = addTheme(api, bob, baseId, {118 name: 'default',119 properties: [],120 });121122 await expectTxFailure(/rmrkEquip\.PermissionError/, tx);123 });124125 after(() => { api.disconnect(); });126});