1234567891011121314151617import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';19import {IKeyringPair} from '@polkadot/types/types';20import {itSub, usingPlaygrounds} from './util/playgrounds';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {26 let alice: IKeyringPair;27 let bob: IKeyringPair;2829 before(async () => {30 await usingPlaygrounds(async (helper, privateKey) => {31 const donor = privateKey('//Alice');32 [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);33 });34 });3536 itSub('Remove collection admin', async ({helper}) => {37 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-1', tokenPrefix: 'RCA'});38 const collectionInfo = await collection.getData();39 expect(collectionInfo?.raw.owner.toString()).to.be.deep.eq(alice.address);40 41 await collection.addAdmin(alice, {Substrate: bob.address});4243 const adminListAfterAddAdmin = await collection.getAdmins();44 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});4546 47 await collection.removeAdmin(alice, {Substrate: bob.address});4849 const adminListAfterRemoveAdmin = await collection.getAdmins();50 expect(adminListAfterRemoveAdmin).not.to.be.deep.contains({Substrate: bob.address});51 });5253 itSub('Remove admin from collection that has no admins', async ({helper}) => {54 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-2', tokenPrefix: 'RCA'});5556 const adminListBeforeAddAdmin = await collection.getAdmins();57 expect(adminListBeforeAddAdmin).to.have.lengthOf(0);5859 await collection.removeAdmin(alice, {Substrate: alice.address});60 });61});6263describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {64 let alice: IKeyringPair;65 let bob: IKeyringPair;66 let charlie: IKeyringPair;6768 before(async () => {69 await usingPlaygrounds(async (helper, privateKey) => {70 const donor = privateKey('//Alice');71 [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);72 });73 });7475 itSub('Can\'t remove collection admin from not existing collection', async ({helper}) => {76 const collectionId = (1 << 32) - 1;7778 await expect(helper.collection.removeAdmin(alice, collectionId, {Substrate: bob.address}))79 .to.be.rejectedWith(/common\.CollectionNotFound/);80 });8182 itSub('Can\'t remove collection admin from deleted collection', async ({helper}) => {83 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-Neg-2', tokenPrefix: 'RCA'});8485 expect(await collection.burn(alice)).to.be.true;8687 await expect(helper.collection.removeAdmin(alice, collection.collectionId, {Substrate: bob.address}))88 .to.be.rejectedWith(/common\.CollectionNotFound/);89 });9091 itSub('Regular user can\'t remove collection admin', async ({helper}) => {92 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-Neg-3', tokenPrefix: 'RCA'});9394 await collection.addAdmin(alice, {Substrate: bob.address});9596 await expect(collection.removeAdmin(charlie, {Substrate: bob.address}))97 .to.be.rejectedWith(/common\.NoPermission/);98 });99100 itSub('Admin can\'t remove collection admin.', async ({helper}) => {101 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-Neg-4', tokenPrefix: 'RCA'});102 103 await collection.addAdmin(alice, {Substrate: bob.address});104 await collection.addAdmin(alice, {Substrate: charlie.address});105106 const adminListAfterAddAdmin = await collection.getAdmins();107 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});108 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: charlie.address});109110 await expect(collection.removeAdmin(charlie, {Substrate: bob.address}))111 .to.be.rejectedWith(/common\.NoPermission/);112113 const adminListAfterRemoveAdmin = await collection.getAdmins();114 expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: bob.address});115 expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: charlie.address});116 });117});