Эх сурвалжийг харах

Cont_directory integration tests: Fix prettier warnings

iorveth 4 жил өмнө
parent
commit
40dbe6d396

+ 72 - 60
tests/network-tests/src/Api.ts

@@ -30,12 +30,11 @@ import {
 } from '@joystream/types/hiring'
 import { FillOpeningParameters, ProposalId } from '@joystream/types/proposals'
 import { v4 as uuid } from 'uuid'
-import { InputParser } from 'cd-schemas'
 import { ChannelEntity } from 'cd-schemas/types/entities/ChannelEntity'
 import { VideoEntity } from 'cd-schemas/types/entities/VideoEntity'
-import { initializeContentDir, ExtrinsicsHelper } from 'cd-schemas'
-import { OperationType } from '@joystream/types/content-directory';
-import { gql, ApolloClient, ApolloQueryResult, NormalizedCacheObject } from '@apollo/client';
+import { initializeContentDir, InputParser, ExtrinsicsHelper } from 'cd-schemas'
+import { OperationType } from '@joystream/types/content-directory'
+import { gql, ApolloClient, ApolloQueryResult, NormalizedCacheObject } from '@apollo/client'
 
 import Debugger from 'debug'
 const debug = Debugger('api')
@@ -1927,75 +1926,82 @@ export class Api {
   }
 
   async sendContentDirectoryTransaction(operations: OperationType[], pair: KeyringPair): Promise<void> {
+    const transaction = this.api.tx.contentDirectory.transaction(
+      { Lead: null }, // We use member with id 0 as actor (in this case we assume this is Alice)
+      operations // We provide parsed operations as second argument
+    )
 
-    const transaction = this.api.tx.contentDirectory
-      .transaction(
-        { Lead: null }, // We use member with id 0 as actor (in this case we assume this is Alice)
-        operations // We provide parsed operations as second argument
-      )
-
-      const txHelper = new ExtrinsicsHelper(this.api)
-      await txHelper.sendAndCheck(pair, [transaction], 'Transaction failed!')
+    const txHelper = new ExtrinsicsHelper(this.api)
+    await txHelper.sendAndCheck(pair, [transaction], 'Transaction failed!')
   }
 
   public async createChannelEntity(channel: ChannelEntity, pair: KeyringPair): Promise<void> {
     // Create the parser with known entity schemas (the ones in content-directory-schemas/inputs)
-  const parser = InputParser.createWithKnownSchemas(
-    this.api,
-    // The second argument is an array of entity batches, following standard entity batch syntax ({ className, entries }):
-    [
-      {
-        className: 'Channel',
-        entries: [channel], // We could specify multiple entries here, but in this case we only need one
-      },
-    ]
-  )
-  // We parse the input into CreateEntity and AddSchemaSupportToEntity operations
-  const operations = await parser.getEntityBatchOperations()
-  return await this.sendContentDirectoryTransaction(operations, pair)
+    const parser = InputParser.createWithKnownSchemas(
+      this.api,
+      // The second argument is an array of entity batches, following standard entity batch syntax ({ className, entries }):
+      [
+        {
+          className: 'Channel',
+          entries: [channel], // We could specify multiple entries here, but in this case we only need one
+        },
+      ]
+    )
+    // We parse the input into CreateEntity and AddSchemaSupportToEntity operations
+    const operations = await parser.getEntityBatchOperations()
+    return await this.sendContentDirectoryTransaction(operations, pair)
   }
 
   public async createVideoEntity(video: VideoEntity, pair: KeyringPair): Promise<void> {
     // Create the parser with known entity schemas (the ones in content-directory-schemas/inputs)
-  const parser = InputParser.createWithKnownSchemas(
-    this.api,
-    // The second argument is an array of entity batches, following standard entity batch syntax ({ className, entries }):
-    [
-      {
-        className: 'Video',
-        entries: [video], // We could specify multiple entries here, but in this case we only need one
-      },
-    ]
-  )
-  // We parse the input into CreateEntity and AddSchemaSupportToEntity operations
-  const operations = await parser.getEntityBatchOperations()
-  return await this.sendContentDirectoryTransaction(operations, pair)
-  }
-
-  public async updateChannelEntity(channelUpdateInput: Record<string, any>, uniquePropValue: Record<string, any>, pair: KeyringPair): Promise<void> {
+    const parser = InputParser.createWithKnownSchemas(
+      this.api,
+      // The second argument is an array of entity batches, following standard entity batch syntax ({ className, entries }):
+      [
+        {
+          className: 'Video',
+          entries: [video], // We could specify multiple entries here, but in this case we only need one
+        },
+      ]
+    )
+    // We parse the input into CreateEntity and AddSchemaSupportToEntity operations
+    const operations = await parser.getEntityBatchOperations()
+    return await this.sendContentDirectoryTransaction(operations, pair)
+  }
+
+  public async updateChannelEntity(
+    channelUpdateInput: Record<string, any>,
+    uniquePropValue: Record<string, any>,
+    pair: KeyringPair
+  ): Promise<void> {
     // Create the parser with known entity schemas (the ones in content-directory-schemas/inputs)
-  const parser = InputParser.createWithKnownSchemas(this.api)
+    const parser = InputParser.createWithKnownSchemas(this.api)
 
-  // We can reuse InputParser's `findEntityIdByUniqueQuery` method to find entityId of the channel we
-  // created in ./createChannel.ts example (normally we would probably use some other way to do it, ie.: query node)
-  const CHANNEL_ID = await parser.findEntityIdByUniqueQuery(uniquePropValue, 'Channel')// Use getEntityUpdateOperations to parse the update input
-  const updateOperations = await parser.getEntityUpdateOperations(
-    channelUpdateInput,
-    'Channel', // Class name
-    CHANNEL_ID // Id of the entity we want to update
-  )
-  return await this.sendContentDirectoryTransaction(updateOperations, pair)
+    // We can reuse InputParser's `findEntityIdByUniqueQuery` method to find entityId of the channel we
+    // created in ./createChannel.ts example (normally we would probably use some other way to do it, ie.: query node)
+    const CHANNEL_ID = await parser.findEntityIdByUniqueQuery(uniquePropValue, 'Channel') // Use getEntityUpdateOperations to parse the update input
+    const updateOperations = await parser.getEntityUpdateOperations(
+      channelUpdateInput,
+      'Channel', // Class name
+      CHANNEL_ID // Id of the entity we want to update
+    )
+    return await this.sendContentDirectoryTransaction(updateOperations, pair)
   }
 
   public async initializeContentDirectory(leadKeyPair: KeyringPair) {
-    await initializeContentDir(this.api,  leadKeyPair)
+    await initializeContentDir(this.api, leadKeyPair)
   }
 }
 
 export class QueryNodeApi extends Api {
   private readonly queryNodeProvider: ApolloClient<NormalizedCacheObject>
 
-  public static async new(provider: WsProvider, queryNodeProvider: ApolloClient<NormalizedCacheObject>, treasuryAccountUri: string, sudoAccountUri: string): Promise<QueryNodeApi> {
+  public static async new(
+    provider: WsProvider,
+    queryNodeProvider: ApolloClient<NormalizedCacheObject>,
+    treasuryAccountUri: string,
+    sudoAccountUri: string
+  ): Promise<QueryNodeApi> {
     let connectAttempts = 0
     while (true) {
       connectAttempts++
@@ -2020,25 +2026,31 @@ export class QueryNodeApi extends Api {
     }
   }
 
-  constructor(api: ApiPromise, queryNodeProvider: ApolloClient<NormalizedCacheObject>, treasuryAccountUri: string, sudoAccountUri: string) {
+  constructor(
+    api: ApiPromise,
+    queryNodeProvider: ApolloClient<NormalizedCacheObject>,
+    treasuryAccountUri: string,
+    sudoAccountUri: string
+  ) {
     super(api, treasuryAccountUri, sudoAccountUri)
     this.queryNodeProvider = queryNodeProvider
   }
 
-  public async getChannelbyTitle(channel_title: string): Promise<ApolloQueryResult<any>> {
+  public async getChannelbyTitle(channelTitle: string): Promise<ApolloQueryResult<any>> {
     const GET_CHANNEL_BY_TITLE = gql`
-      query getChannelbyTitle($title: String) {
+      query($title: String) {
         channels(title: $title) {
           title
           description
-          language
           coverPhotoUrl
-          avatarPhotoURL
+          avatarPhotoUrl
           isPublic
+          isCurated
+          languageId
         }
       }
-    `;
+    `
 
-    return await this.queryNodeProvider.query({query: GET_CHANNEL_BY_TITLE, variables: [channel_title]})
+    return await this.queryNodeProvider.query({ query: GET_CHANNEL_BY_TITLE, variables: [channelTitle] })
   }
 }

+ 7 - 5
tests/network-tests/src/fixtures/contentDirectoryModule.ts

@@ -23,7 +23,6 @@ export class CreateChannelFixture implements Fixture {
   public async runner(expectFailure: boolean): Promise<void> {
     await this.api.createChannelEntity(this.channelEntity, this.pair)
 
-
     if (expectFailure) {
       throw new Error('Successful fixture run while expecting failure')
     }
@@ -44,7 +43,6 @@ export class CreateVideoFixture implements Fixture {
   public async runner(expectFailure: boolean): Promise<void> {
     await this.api.createVideoEntity(this.videoEntity, this.pair)
 
-
     if (expectFailure) {
       throw new Error('Successful fixture run while expecting failure')
     }
@@ -57,7 +55,12 @@ export class UpdateChannelFixture implements Fixture {
   private channelUpdateInput: Record<string, any>
   private uniquePropValue: Record<string, any>
 
-  public constructor(api: QueryNodeApi, channelUpdateInput: Record<string, any>, uniquePropValue: Record<string, any>, pair: KeyringPair) {
+  public constructor(
+    api: QueryNodeApi,
+    channelUpdateInput: Record<string, any>,
+    uniquePropValue: Record<string, any>,
+    pair: KeyringPair
+  ) {
     this.api = api
     this.channelUpdateInput = channelUpdateInput
     this.uniquePropValue = uniquePropValue
@@ -67,9 +70,8 @@ export class UpdateChannelFixture implements Fixture {
   public async runner(expectFailure: boolean): Promise<void> {
     await this.api.updateChannelEntity(this.channelUpdateInput, this.uniquePropValue, this.pair)
 
-
     if (expectFailure) {
       throw new Error('Successful fixture run while expecting failure')
     }
   }
-}
+}

+ 2 - 3
tests/network-tests/src/flows/contentDirectory/contentDirectoryInitialization.ts

@@ -3,6 +3,5 @@ import { assert } from 'chai'
 import { KeyringPair } from '@polkadot/keyring/types'
 
 export default async function initializeContentDirectory(api: Api, leadKeyPair: KeyringPair) {
-    await api.initializeContentDirectory(leadKeyPair)
-
-}
+  await api.initializeContentDirectory(leadKeyPair)
+}

+ 24 - 20
tests/network-tests/src/flows/contentDirectory/creatingChannel.ts

@@ -6,17 +6,17 @@ import { KeyringPair } from '@polkadot/keyring/types'
 
 export function createSimpleChannelFixture(api: QueryNodeApi, pair: KeyringPair): CreateChannelFixture {
   const channelEntity: ChannelEntity = {
-      title: 'Example channel',
-      description: 'This is an example channel',
-      // We can use "existing" syntax to reference either an on-chain entity or other entity that's part of the same batch.
-      // Here we reference language that we assume was added by initialization script (initialize:dev), as it is part of
-      // input/entityBatches/LanguageBatch.json
-      language: { existing: { code: 'EN' } },
-      coverPhotoUrl: '',
-      avatarPhotoURL: '',
-      isPublic: true,
-    }
-    return new CreateChannelFixture (api, channelEntity, pair)
+    title: 'Example channel',
+    description: 'This is an example channel',
+    // We can use "existing" syntax to reference either an on-chain entity or other entity that's part of the same batch.
+    // Here we reference language that we assume was added by initialization script (initialize:dev), as it is part of
+    // input/entityBatches/LanguageBatch.json
+    language: { existing: { code: 'EN' } },
+    coverPhotoUrl: '',
+    avatarPhotoURL: '',
+    isPublic: true,
+  }
+  return new CreateChannelFixture(api, channelEntity, pair)
 }
 
 export default async function channelCreation(api: QueryNodeApi, pair: KeyringPair) {
@@ -24,13 +24,17 @@ export default async function channelCreation(api: QueryNodeApi, pair: KeyringPa
 
   await createChannelHappyCaseFixture.runner(false)
 
-  const data = await api.getChannelbyTitle(createChannelHappyCaseFixture.channelEntity.title).then(result => result.data)
+  const data = await api
+    .getChannelbyTitle(createChannelHappyCaseFixture.channelEntity.title)
+    .then((result) => result.data)
 
-  assert(data.title === createChannelHappyCaseFixture.channelEntity.title, "Should be equal")
-  assert(data.description === createChannelHappyCaseFixture.channelEntity.description, "Should be equal")
-  assert(data.language === createChannelHappyCaseFixture.channelEntity.language as unknown as string, "Should be equal")
-  assert(data.coverPhotoUrl === createChannelHappyCaseFixture.channelEntity.coverPhotoUrl, "Should be equal")
-  assert(data.avatarPhotoURL === createChannelHappyCaseFixture.channelEntity.avatarPhotoURL, "Should be equal")
-  assert(data.isPublic === createChannelHappyCaseFixture.channelEntity.isPublic.toString(), "Should be equal")
-
-}
+  assert(data.title === createChannelHappyCaseFixture.channelEntity.title, 'Should be equal')
+  assert(data.description === createChannelHappyCaseFixture.channelEntity.description, 'Should be equal')
+  assert(
+    data.language === ((createChannelHappyCaseFixture.channelEntity.language as unknown) as string),
+    'Should be equal'
+  )
+  assert(data.coverPhotoUrl === createChannelHappyCaseFixture.channelEntity.coverPhotoUrl, 'Should be equal')
+  assert(data.avatarPhotoURL === createChannelHappyCaseFixture.channelEntity.avatarPhotoURL, 'Should be equal')
+  assert(data.isPublic === createChannelHappyCaseFixture.channelEntity.isPublic.toString(), 'Should be equal')
+}

+ 35 - 35
tests/network-tests/src/flows/contentDirectory/creatingVideo.ts

@@ -5,46 +5,46 @@ import { assert } from 'chai'
 import { KeyringPair } from '@polkadot/keyring/types'
 
 export function createVideoReferencingChannelFixture(api: QueryNodeApi, pair: KeyringPair): CreateVideoFixture {
-    const videoEntity: VideoEntity = {
-      title: 'Example video',
-      description: 'This is an example video',
-      // We reference existing language and category by their unique properties with "existing" syntax
-      // (those referenced here are part of inputs/entityBatches)
-      language: { existing: { code: 'EN' } },
-      category: { existing: { name: 'Education' } },
-      // We use the same "existing" syntax to reference a channel by unique property (title)
-      // In this case it's a channel that we created in createChannel example
-      channel: { existing: { title: 'Example channel' } },
-      media: {
-        // We use "new" syntax to sygnalize we want to create a new VideoMedia entity that will be related to this Video entity
-        new: {
-          // We use "exisiting" enconding from inputs/entityBatches/VideoMediaEncodingBatch.json
-          encoding: { existing: { name: 'H.263_MP4' } },
-          pixelHeight: 600,
-          pixelWidth: 800,
-          // We create nested VideoMedia->MediaLocation->HttpMediaLocation relations using the "new" syntax
-          location: { new: { httpMediaLocation: { new: { url: 'https://testnet.joystream.org/' } } } },
-        },
+  const videoEntity: VideoEntity = {
+    title: 'Example video',
+    description: 'This is an example video',
+    // We reference existing language and category by their unique properties with "existing" syntax
+    // (those referenced here are part of inputs/entityBatches)
+    language: { existing: { code: 'EN' } },
+    category: { existing: { name: 'Education' } },
+    // We use the same "existing" syntax to reference a channel by unique property (title)
+    // In this case it's a channel that we created in createChannel example
+    channel: { existing: { title: 'Example channel' } },
+    media: {
+      // We use "new" syntax to sygnalize we want to create a new VideoMedia entity that will be related to this Video entity
+      new: {
+        // We use "exisiting" enconding from inputs/entityBatches/VideoMediaEncodingBatch.json
+        encoding: { existing: { name: 'H.263_MP4' } },
+        pixelHeight: 600,
+        pixelWidth: 800,
+        // We create nested VideoMedia->MediaLocation->HttpMediaLocation relations using the "new" syntax
+        location: { new: { httpMediaLocation: { new: { url: 'https://testnet.joystream.org/' } } } },
       },
-      // Here we use combined "new" and "existing" syntaxes to create Video->License->KnownLicense relations
-      license: {
-        new: {
-          knownLicense: {
-            // This license can be found in inputs/entityBatches/KnownLicenseBatch.json
-            existing: { code: 'CC_BY' },
-          },
+    },
+    // Here we use combined "new" and "existing" syntaxes to create Video->License->KnownLicense relations
+    license: {
+      new: {
+        knownLicense: {
+          // This license can be found in inputs/entityBatches/KnownLicenseBatch.json
+          existing: { code: 'CC_BY' },
         },
       },
-      duration: 3600,
-      thumbnailURL: '',
-      isExplicit: false,
-      isPublic: true,
-    }
-    return new CreateVideoFixture (api, videoEntity, pair)
+    },
+    duration: 3600,
+    thumbnailURL: '',
+    isExplicit: false,
+    isPublic: true,
+  }
+  return new CreateVideoFixture(api, videoEntity, pair)
 }
 
 export default async function createVideo(api: QueryNodeApi, pair: KeyringPair) {
   const createVideoHappyCaseFixture = createVideoReferencingChannelFixture(api, pair)
- 
+
   await createVideoHappyCaseFixture.runner(false)
-}
+}

+ 5 - 5
tests/network-tests/src/flows/contentDirectory/updatingChannel.ts

@@ -5,18 +5,18 @@ import { assert } from 'chai'
 import { KeyringPair } from '@polkadot/keyring/types'
 
 export function createUpdateChannelTitleFixture(api: QueryNodeApi, pair: KeyringPair): UpdateChannelFixture {
-     // Create partial channel entity, only containing the fields we wish to update
+  // Create partial channel entity, only containing the fields we wish to update
   const channelUpdateInput: Partial<ChannelEntity> = {
     title: 'Updated channel title',
   }
 
   const uniquePropVal: Record<string, any> = { title: 'Example channel' }
-  
-    return new UpdateChannelFixture (api, channelUpdateInput, uniquePropVal, pair)
+
+  return new UpdateChannelFixture(api, channelUpdateInput, uniquePropVal, pair)
 }
 
 export default async function updateChannel(api: QueryNodeApi, pair: KeyringPair) {
   const createVideoHappyCaseFixture = createUpdateChannelTitleFixture(api, pair)
- 
+
   await createVideoHappyCaseFixture.runner(false)
-}
+}

+ 5 - 1
tests/network-tests/src/flows/workingGroup/leaderSetup.ts

@@ -6,7 +6,11 @@ import { assert } from 'chai'
 import { KeyringPair } from '@polkadot/keyring/types'
 
 // Worker application happy case scenario
-export default async function leaderSetup(api: Api, env: NodeJS.ProcessEnv, group: WorkingGroups): Promise<KeyringPair> {
+export default async function leaderSetup(
+  api: Api,
+  env: NodeJS.ProcessEnv,
+  group: WorkingGroups
+): Promise<KeyringPair> {
   const lead = await api.getGroupLead(group)
 
   assert(!lead, `Lead is already set`)

+ 10 - 5
tests/network-tests/src/scenarios/content-directory.ts

@@ -6,7 +6,7 @@ import initializeContentDirectory from '../flows/contentDirectory/contentDirecto
 import createChannel from '../flows/contentDirectory/creatingChannel'
 import createVideo from '../flows/contentDirectory/creatingVideo'
 import updateChannel from '../flows/contentDirectory/updatingChannel'
-import { ApolloClient, InMemoryCache } from '@apollo/client';
+import { ApolloClient, InMemoryCache } from '@apollo/client'
 
 const scenario = async () => {
   // Load env variables
@@ -21,10 +21,15 @@ const scenario = async () => {
 
   const queryNodeProvider = new ApolloClient({
     uri: queryNodeUrl,
-    cache: new InMemoryCache()
-  });
+    cache: new InMemoryCache(),
+  })
 
-  const api: QueryNodeApi = await QueryNodeApi.new(provider, queryNodeProvider, env.TREASURY_ACCOUNT_URI || '//Alice', env.SUDO_ACCOUNT_URI || '//Alice')
+  const api: QueryNodeApi = await QueryNodeApi.new(
+    provider,
+    queryNodeProvider,
+    env.TREASURY_ACCOUNT_URI || '//Alice',
+    env.SUDO_ACCOUNT_URI || '//Alice'
+  )
 
   const leadKeyPair = await leaderSetup(api, env, WorkingGroups.ContentDirectoryWorkingGroup)
 
@@ -38,7 +43,7 @@ const scenario = async () => {
   await createVideo(api, leadKeyPair)
 
   await updateChannel(api, leadKeyPair)
-  
+
   // Note: disconnecting and then reconnecting to the chain in the same process
   // doesn't seem to work!
   api.close()