1234567891011121314151617import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';19import {usingPlaygrounds} from './util/playgrounds';2021chai.use(chaiAsPromised);22const expect = chai.expect;2324describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {25 it('Remove collection admin.', async () => {26 await usingPlaygrounds(async (helper, privateKey) => {27 const alice = privateKey('//Alice');28 const bob = privateKey('//Bob');29 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});30 31 const collectionInfo = await collection.getData();32 expect(collectionInfo?.raw.owner.toString()).to.be.deep.eq(alice.address);33 34 await collection.addAdmin(alice, {Substrate: bob.address});3536 const adminListAfterAddAdmin = await collection.getAdmins();37 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});3839 40 await collection.removeAdmin(alice, {Substrate: bob.address});4142 const adminListAfterRemoveAdmin = await collection.getAdmins();43 expect(adminListAfterRemoveAdmin).not.to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});44 });45 });4647 it('Remove admin from collection that has no admins', async () => {48 await usingPlaygrounds(async (helper, privateKey) => {49 const alice = privateKey('//Alice');50 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});5152 const adminListBeforeAddAdmin = await collection.getAdmins();53 expect(adminListBeforeAddAdmin).to.have.lengthOf(0);5455 56 await collection.removeAdmin(alice, {Substrate: alice.address});57 });58 });59});6061describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {62 it('Can\'t remove collection admin from not existing collection', async () => {63 await usingPlaygrounds(async (helper, privateKey) => {64 65 const collectionId = (1 << 32) - 1;66 const alice = privateKey('//Alice');67 const bob = privateKey('//Bob');6869 await expect(helper.collection.removeAdmin(alice, collectionId, {Substrate: bob.address})).to.be.rejected;7071 72 await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});73 });74 });7576 it('Can\'t remove collection admin from deleted collection', async () => {77 await usingPlaygrounds(async (helper, privateKey) => {78 const alice = privateKey('//Alice');79 const bob = privateKey('//Bob');80 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});8182 expect(await collection.burn(alice)).to.be.true;8384 await expect(helper.collection.removeAdmin(alice, collection.collectionId, {Substrate: bob.address})).to.be.rejected;8586 87 await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});88 });89 });9091 it('Regular user can\'t remove collection admin', async () => {92 await usingPlaygrounds(async (helper, privateKey) => {93 const alice = privateKey('//Alice');94 const bob = privateKey('//Bob');95 const charlie = privateKey('//Charlie');96 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});9798 await collection.addAdmin(alice, {Substrate: bob.address});99100 await expect(collection.removeAdmin(charlie, {Substrate: bob.address})).to.be.rejected;101102 103 await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});104 });105 });106107 it('Admin can\'t remove collection admin.', async () => {108 await usingPlaygrounds(async (helper, privateKey) => {109 const alice = privateKey('//Alice');110 const bob = privateKey('//Bob');111 const charlie = privateKey('//Charlie');112 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});113 114 await collection.addAdmin(alice, {Substrate: bob.address});115 await collection.addAdmin(alice, {Substrate: charlie.address});116117 const adminListAfterAddAdmin = await collection.getAdmins();118 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});119 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(charlie.address)});120121 await expect(collection.removeAdmin(charlie, {Substrate: bob.address})).to.be.rejected;122123 const adminListAfterRemoveAdmin = await collection.getAdmins();124 expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});125 expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(charlie.address)});126 });127 });128});