Browse Source

Complete channel creation flow

iorveth 4 years ago
parent
commit
6641ada449

+ 1 - 1
tests/network-tests/.env

@@ -1,7 +1,7 @@
 # Address of the Joystream node.
 NODE_URL = ws://127.0.0.1:9944
 # Address of the Joystream query node.
-QUERY_NODE_URL = ws://127.0.0.1:4000
+QUERY_NODE_URL = http://127.0.0.1:4000/graphql
 # Account which is expected to provide sufficient funds to test accounts.
 TREASURY_ACCOUNT_URI = //Alice
 # Sudo Account

+ 22 - 5
tests/network-tests/src/Api.ts

@@ -35,7 +35,7 @@ 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, NormalizedCacheObject } from '@apollo/client';
+import { gql, ApolloClient, ApolloQueryResult, NormalizedCacheObject } from '@apollo/client';
 
 import Debugger from 'debug'
 const debug = Debugger('api')
@@ -46,11 +46,11 @@ export enum WorkingGroups {
 }
 
 export class Api {
-  private readonly api: ApiPromise
-  private readonly sender: Sender
-  private readonly keyring: Keyring
+  protected readonly api: ApiPromise
+  protected readonly sender: Sender
+  protected readonly keyring: Keyring
   // source of funds for all new accounts
-  private readonly treasuryAccount: string
+  protected readonly treasuryAccount: string
 
   public static async create(provider: WsProvider, treasuryAccountUri: string, sudoAccountUri: string): Promise<Api> {
     let connectAttempts = 0
@@ -2024,4 +2024,21 @@ export class QueryNodeApi extends Api {
     super(api, treasuryAccountUri, sudoAccountUri)
     this.queryNodeProvider = queryNodeProvider
   }
+
+  public async getChannelbyTitle(channel_title: string): Promise<ApolloQueryResult<any>> {
+    const GET_CHANNEL_BY_TITLE = gql`
+      query getChannelbyTitle($title: String) {
+        channels(title: $title) {
+          title
+          description
+          language
+          coverPhotoUrl
+          avatarPhotoURL
+          isPublic
+        }
+      }
+    `;
+
+    return await this.queryNodeProvider.query({query: GET_CHANNEL_BY_TITLE, variables: [channel_title]})
+  }
 }

+ 8 - 8
tests/network-tests/src/fixtures/contentDirectoryModule.ts

@@ -1,4 +1,4 @@
-import { Api } from '../Api'
+import { QueryNodeApi } from '../Api'
 import BN from 'bn.js'
 import { assert } from 'chai'
 import { Seat } from '@joystream/types/council'
@@ -10,11 +10,11 @@ import { VideoEntity } from 'cd-schemas/types/entities/VideoEntity'
 import { KeyringPair } from '@polkadot/keyring/types'
 
 export class CreateChannelFixture implements Fixture {
-  private api: Api
-  private channelEntity: ChannelEntity
+  private api: QueryNodeApi
+  public channelEntity: ChannelEntity
   private pair: KeyringPair
 
-  public constructor(api: Api,  channelEntity: ChannelEntity, pair: KeyringPair) {
+  public constructor(api: QueryNodeApi, channelEntity: ChannelEntity, pair: KeyringPair) {
     this.api = api
     this.pair = pair
     this.channelEntity = channelEntity
@@ -31,11 +31,11 @@ export class CreateChannelFixture implements Fixture {
 }
 
 export class CreateVideoFixture implements Fixture {
-  private api: Api
+  private api: QueryNodeApi
   private pair: KeyringPair
   private videoEntity: VideoEntity
 
-  public constructor(api: Api, videoEntity: VideoEntity, pair: KeyringPair) {
+  public constructor(api: QueryNodeApi, videoEntity: VideoEntity, pair: KeyringPair) {
     this.api = api
     this.videoEntity = videoEntity
     this.pair = pair
@@ -52,12 +52,12 @@ export class CreateVideoFixture implements Fixture {
 }
 
 export class UpdateChannelFixture implements Fixture {
-  private api: Api
+  private api: QueryNodeApi
   private pair: KeyringPair
   private channelUpdateInput: Record<string, any>
   private uniquePropValue: Record<string, any>
 
-  public constructor(api: Api, 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

+ 13 - 3
tests/network-tests/src/flows/contentDirectory/creatingChannel.ts

@@ -1,10 +1,10 @@
-import { Api, WorkingGroups } from '../../Api'
+import { QueryNodeApi, WorkingGroups } from '../../Api'
 import { CreateChannelFixture } from '../../fixtures/contentDirectoryModule'
 import { ChannelEntity } from 'cd-schemas/types/entities/ChannelEntity'
 import { assert } from 'chai'
 import { KeyringPair } from '@polkadot/keyring/types'
 
-export function createSimpleChannelFixture(api: Api, pair: KeyringPair): CreateChannelFixture {
+export function createSimpleChannelFixture(api: QueryNodeApi, pair: KeyringPair): CreateChannelFixture {
   const channelEntity: ChannelEntity = {
       title: 'Example channel',
       description: 'This is an example channel',
@@ -19,8 +19,18 @@ export function createSimpleChannelFixture(api: Api, pair: KeyringPair): CreateC
     return new CreateChannelFixture (api, channelEntity, pair)
 }
 
-export default async function channelCreation(api: Api, pair: KeyringPair) {
+export default async function channelCreation(api: QueryNodeApi, pair: KeyringPair) {
   const createChannelHappyCaseFixture = createSimpleChannelFixture(api, pair)
 
   await createChannelHappyCaseFixture.runner(false)
+
+  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?.toString(), "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")
+
 }

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

@@ -1,10 +1,10 @@
-import { Api, WorkingGroups } from '../../Api'
+import { QueryNodeApi, WorkingGroups } from '../../Api'
 import { CreateVideoFixture } from '../../fixtures/contentDirectoryModule'
 import { VideoEntity } from 'cd-schemas/types/entities/VideoEntity'
 import { assert } from 'chai'
 import { KeyringPair } from '@polkadot/keyring/types'
 
-export function createVideoReferencingChannelFixture(api: Api, pair: KeyringPair): CreateVideoFixture {
+export function createVideoReferencingChannelFixture(api: QueryNodeApi, pair: KeyringPair): CreateVideoFixture {
     const videoEntity: VideoEntity = {
       title: 'Example video',
       description: 'This is an example video',
@@ -43,7 +43,7 @@ export function createVideoReferencingChannelFixture(api: Api, pair: KeyringPair
     return new CreateVideoFixture (api, videoEntity, pair)
 }
 
-export default async function createVideo(api: Api, pair: KeyringPair) {
+export default async function createVideo(api: QueryNodeApi, pair: KeyringPair) {
   const createVideoHappyCaseFixture = createVideoReferencingChannelFixture(api, pair)
  
   await createVideoHappyCaseFixture.runner(false)

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

@@ -1,10 +1,10 @@
-import { Api, WorkingGroups } from '../../Api'
+import { QueryNodeApi, WorkingGroups } from '../../Api'
 import { UpdateChannelFixture } from '../../fixtures/contentDirectoryModule'
 import { ChannelEntity } from 'cd-schemas/types/entities/ChannelEntity'
 import { assert } from 'chai'
 import { KeyringPair } from '@polkadot/keyring/types'
 
-export function createUpdateChannelTitleFixture(api: Api, pair: KeyringPair): UpdateChannelFixture {
+export function createUpdateChannelTitleFixture(api: QueryNodeApi, pair: KeyringPair): UpdateChannelFixture {
      // Create partial channel entity, only containing the fields we wish to update
   const channelUpdateInput: Partial<ChannelEntity> = {
     title: 'Updated channel title',
@@ -15,7 +15,7 @@ export function createUpdateChannelTitleFixture(api: Api, pair: KeyringPair): Up
     return new UpdateChannelFixture (api, channelUpdateInput, uniquePropVal, pair)
 }
 
-export default async function updateChannel(api: Api, pair: KeyringPair) {
+export default async function updateChannel(api: QueryNodeApi, pair: KeyringPair) {
   const createVideoHappyCaseFixture = createUpdateChannelTitleFixture(api, pair)
  
   await createVideoHappyCaseFixture.runner(false)

+ 1 - 1
tests/network-tests/src/scenarios/content-directory.ts

@@ -17,7 +17,7 @@ const scenario = async () => {
   const nodeUrl: string = env.NODE_URL || 'ws://127.0.0.1:9944'
   const provider = new WsProvider(nodeUrl)
 
-  const queryNodeUrl: string = env.QUERY_NODE_URL || 'ws://127.0.0.1:4000'
+  const queryNodeUrl: string = env.QUERY_NODE_URL || 'http://127.0.0.1:4000/graphql'
 
   const queryNodeProvider = new ApolloClient({
     uri: queryNodeUrl,