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 const collectionInfo = await collection.getData();31 expect(collectionInfo?.raw.owner.toString()).to.be.deep.eq(alice.address);32 33 await collection.addAdmin(alice, {Substrate: bob.address});3435 const adminListAfterAddAdmin = await collection.getAdmins();36 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});3738 39 await collection.removeAdmin(alice, {Substrate: bob.address});4041 const adminListAfterRemoveAdmin = await collection.getAdmins();42 expect(adminListAfterRemoveAdmin).not.to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});43 });44 });4546 it('Remove admin from collection that has no admins', async () => {47 await usingPlaygrounds(async (helper, privateKey) => {48 const alice = privateKey('//Alice');49 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});5051 const adminListBeforeAddAdmin = await collection.getAdmins();52 expect(adminListBeforeAddAdmin).to.have.lengthOf(0);5354 55 await collection.removeAdmin(alice, {Substrate: alice.address});56 });57 });58});5960describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {61 it('Can\'t remove collection admin from not existing collection', async () => {62 await usingPlaygrounds(async (helper, privateKey) => {63 64 const collectionId = (1 << 32) - 1;65 const alice = privateKey('//Alice');66 const bob = privateKey('//Bob');6768 await expect(helper.collection.removeAdmin(alice, collectionId, {Substrate: bob.address})).to.be.rejected;6970 71 await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});72 });73 });7475 it('Can\'t remove collection admin from deleted collection', async () => {76 await usingPlaygrounds(async (helper, privateKey) => {77 const alice = privateKey('//Alice');78 const bob = privateKey('//Bob');79 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});8081 expect(await collection.burn(alice)).to.be.true;8283 await expect(helper.collection.removeAdmin(alice, collection.collectionId, {Substrate: bob.address})).to.be.rejected;8485 86 await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});87 });88 });8990 it('Regular user can\'t remove collection admin', async () => {91 await usingPlaygrounds(async (helper, privateKey) => {92 const alice = privateKey('//Alice');93 const bob = privateKey('//Bob');94 const charlie = privateKey('//Charlie');95 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});9697 await collection.addAdmin(alice, {Substrate: bob.address});9899 await expect(collection.removeAdmin(charlie, {Substrate: bob.address})).to.be.rejected;100101 102 await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});103 });104 });105106 it('Admin can\'t remove collection admin.', async () => {107 await usingPlaygrounds(async (helper, privateKey) => {108 const alice = privateKey('//Alice');109 const bob = privateKey('//Bob');110 const charlie = privateKey('//Charlie');111 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});112 113 await collection.addAdmin(alice, {Substrate: bob.address});114 await collection.addAdmin(alice, {Substrate: charlie.address});115116 const adminListAfterAddAdmin = await collection.getAdmins();117 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});118 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(charlie.address)});119120 await expect(collection.removeAdmin(charlie, {Substrate: bob.address})).to.be.rejected;121122 const adminListAfterRemoveAdmin = await collection.getAdmins();123 expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});124 expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(charlie.address)});125 });126 });127});