git.delta.rocks / unique-network / refs/commits / d05c19b445d1

difftreelog

source

tests/src/rmrk/addTheme.seqtest.ts3.5 KiBsourcehistory
1import {expect} from 'chai';2import {getApiConnection} from '../substrate/substrate-api';3import {createBase, addTheme} from './util/tx';4import {expectTxFailure, requirePallets, Pallets} from './util/helpers';5import {getThemeNames} from './util/fetch';67describe('integration test: add Theme to Base', () => {8  let api: any;9  before(async function() {10    api = await getApiConnection();11    await requirePallets(this, [Pallets.RmrkEquip]);12  });1314  const alice = '//Alice';15  const bob = '//Bob';1617  it('add default theme', async () => {18    const baseId = await createBase(api, alice, 'default-themed-base', 'DTBase', []);19    await addTheme(api, alice, baseId, {20      name: 'default',21      properties: [22        {23          key: 'some-key',24          value: 'some-key-value',25        },26        {27          key: 'another-key',28          value: 'another-key-value',29        },30      ],31    });32  });3334  it('add default theme and a custom one', async () => {35    const baseId = await createBase(api, alice, '2-themed-base', '2TBase', []);36    await addTheme(api, alice, baseId, {37      name: 'default',38      properties: [39        {40          key: 'default-key',41          value: 'default-key-value',42        },43      ],44    });45    await addTheme(api, alice, baseId, {46      name: 'custom-theme',47      properties: [48        {49          key: 'custom-key-0',50          value: 'custom-key-value-0',51        },52        {53          key: 'custom-key-1',54          value: 'custom-key-value-1',55        },56      ],57    });58  });5960  it('fetch filtered theme keys', async () => {61    const baseId = await createBase(api, alice, '2-themed-base', '2TBase', []);62    await addTheme(api, alice, baseId, {63      name: 'default',64      properties: [65        {66          key: 'first-key',67          value: 'first-key-value',68        },69        {70          key: 'second-key',71          value: 'second-key-value',72        },73      ],74    }, ['second-key']);75  });7677  it('fetch theme names', async() => {78    const baseId = await createBase(api, alice, '3-themed-base', '3TBase', []);79    const names = [80      'default',81      'first-theme',82      'second-theme',83    ];8485    for (let i = 0; i < names.length; i++) {86      await addTheme(api, alice, baseId, {name: names[i], properties: [{key: 'dummy', value: 'dummy'}]});87    }8889    const fetchedNames = await getThemeNames(api, baseId);9091    for (let i = 0; i < names.length; i++) {92      const isFound = fetchedNames.find((name) => name === names[i]) !== undefined;9394      expect(isFound, 'Error: invalid theme names').to.be.true;95    }96  });9798  it('[negative] unable to add theme to non-existing base', async () => {99    const maxBaseId = 0xFFFFFFFF;100    const tx = addTheme(api, alice, maxBaseId, {101      name: 'default',102      properties: [],103    });104105    await expectTxFailure(/rmrkEquip\.BaseDoesntExist/, tx);106  });107108  it('[negative] unable to add custom theme if no default theme', async () => {109    const baseId = await createBase(api, alice, 'no-default-themed-base', 'NDTBase', []);110    const tx = addTheme(api, alice, baseId, {111      name: 'custom-theme',112      properties: [],113    });114115    await expectTxFailure(/rmrkEquip\.NeedsDefaultThemeFirst/, tx);116  });117118  it('[negative] unable to add theme by a not-an-owner', async () => {119    const baseId = await createBase(api, alice, 'no-default-themed-base', 'NDTBase', []);120    const tx = addTheme(api, bob, baseId, {121      name: 'default',122      properties: [],123    });124125    await expectTxFailure(/rmrkEquip\.PermissionError/, tx);126  });127128  after(async() => { await api.disconnect(); });129});