Forráskód Böngészése

Merge pull request #1654 from iorveth/content_directory_integration_tests

Content directory integration tests part 2, part 3
Mokhtar Naamani 4 éve
szülő
commit
11d4f09188

+ 46 - 6
tests/network-tests/src/Api.ts

@@ -2035,21 +2035,61 @@ export class QueryNodeApi extends Api {
     this.queryNodeProvider = queryNodeProvider
   }
 
-  public async getChannelbyTitle(title: string): Promise<ApolloQueryResult<any>> {
+  public async getChannelbyHandle(handle: string): Promise<ApolloQueryResult<any>> {
     const GET_CHANNEL_BY_TITLE = gql`
-      query($title: String!) {
-        channels(where: { title_eq: $title }) {
-          title
+      query($handle: String!) {
+        channels(where: { handle_eq: $handle }) {
+          handle
           description
           coverPhotoUrl
           avatarPhotoUrl
           isPublic
           isCurated
-          languageId
+          videos {
+            title
+            description
+            duration
+            thumbnailUrl
+            isExplicit
+            isPublic
+          }
+        }
+      }
+    `
+
+    return await this.queryNodeProvider.query({ query: GET_CHANNEL_BY_TITLE, variables: { handle } })
+  }
+
+  public async performFullTextSearchOnChannelTitle(text: string): Promise<ApolloQueryResult<any>> {
+    const FULL_TEXT_SEARCH_ON_CHANNEL_TITLE = gql`
+      query($text: String!) {
+        search(text: $text) {
+          item {
+            ... on Channel {
+              handle
+              description
+            }
+          }
+        }
+      }
+    `
+
+    return await this.queryNodeProvider.query({ query: FULL_TEXT_SEARCH_ON_CHANNEL_TITLE, variables: { text } })
+  }
+
+  public async performFullTextSearchOnVideoTitle(text: string): Promise<ApolloQueryResult<any>> {
+    const FULL_TEXT_SEARCH_ON_VIDEO_TITLE = gql`
+      query($text: String!) {
+        search(text: $text) {
+          item {
+            ... on Video {
+              title
+            }
+          }
         }
       }
     `
 
-    return await this.queryNodeProvider.query({ query: GET_CHANNEL_BY_TITLE, variables: { title } })
+    return await this.queryNodeProvider.query({ query: FULL_TEXT_SEARCH_ON_VIDEO_TITLE, variables: { text } })
   }
 }

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

@@ -28,7 +28,7 @@ export class CreateChannelFixture implements Fixture {
 
 export class CreateVideoFixture implements Fixture {
   private api: QueryNodeApi
-  private videoEntity: VideoEntity
+  public videoEntity: VideoEntity
 
   public constructor(api: QueryNodeApi, videoEntity: VideoEntity) {
     this.api = api

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

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

+ 11 - 12
tests/network-tests/src/flows/contentDirectory/creatingChannel.ts

@@ -3,11 +3,10 @@ import { Utils } from '../../utils'
 import { CreateChannelFixture } from '../../fixtures/contentDirectoryModule'
 import { ChannelEntity } from '@joystream/cd-schemas/types/entities/ChannelEntity'
 import { assert } from 'chai'
-import { KeyringPair } from '@polkadot/keyring/types'
 
 export function createSimpleChannelFixture(api: QueryNodeApi): CreateChannelFixture {
   const channelEntity: ChannelEntity = {
-    handle: 'Example channel',
+    handle: 'New channel example',
     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
@@ -20,6 +19,14 @@ export function createSimpleChannelFixture(api: QueryNodeApi): CreateChannelFixt
   return new CreateChannelFixture(api, channelEntity)
 }
 
+function assertChannelMatchQueriedResult(queriedChannel: any, channel: ChannelEntity) {
+  assert.equal(queriedChannel.handle, channel.handle, 'Should be equal')
+  assert.equal(queriedChannel.description, channel.description, 'Should be equal')
+  assert.equal(queriedChannel.coverPhotoUrl, channel.coverPhotoUrl, 'Should be equal')
+  assert.equal(queriedChannel.avatarPhotoUrl, channel.avatarPhotoUrl, 'Should be equal')
+  assert.equal(queriedChannel.isPublic, channel.isPublic, 'Should be equal')
+}
+
 export default async function channelCreation(api: QueryNodeApi) {
   const createChannelHappyCaseFixture = createSimpleChannelFixture(api)
 
@@ -29,15 +36,7 @@ export default async function channelCreation(api: QueryNodeApi) {
   await Utils.wait(120000)
 
   // Ensure newly created channel was parsed by query node
-  const result = await api.getChannelbyTitle(createChannelHappyCaseFixture.channelEntity.handle)
-  const queriedChannel = result.data.channels[0]
+  const result = await api.getChannelbyHandle(createChannelHappyCaseFixture.channelEntity.handle)
 
-  assert(queriedChannel.title === createChannelHappyCaseFixture.channelEntity.handle, 'Should be equal')
-  assert(queriedChannel.description === createChannelHappyCaseFixture.channelEntity.description, 'Should be equal')
-  assert(queriedChannel.coverPhotoUrl === createChannelHappyCaseFixture.channelEntity.coverPhotoUrl, 'Should be equal')
-  assert(
-    queriedChannel.avatarPhotoUrl === createChannelHappyCaseFixture.channelEntity.avatarPhotoUrl,
-    'Should be equal'
-  )
-  assert(queriedChannel.isPublic === createChannelHappyCaseFixture.channelEntity.isPublic, 'Should be equal')
+  assertChannelMatchQueriedResult(result.data.channels[0], createChannelHappyCaseFixture.channelEntity)
 }

+ 62 - 4
tests/network-tests/src/flows/contentDirectory/creatingVideo.ts

@@ -1,9 +1,10 @@
-import { QueryNodeApi, WorkingGroups } from '../../Api'
+import { QueryNodeApi } from '../../Api'
 import { CreateVideoFixture } from '../../fixtures/contentDirectoryModule'
 import { VideoEntity } from '@joystream/cd-schemas/types/entities/VideoEntity'
 import { assert } from 'chai'
+import { Utils } from '../../utils'
 
-export function createVideoReferencingChannelFixture(api: QueryNodeApi): CreateVideoFixture {
+export function createVideoReferencingChannelFixture(api: QueryNodeApi, handle: string): CreateVideoFixture {
   const videoEntity: VideoEntity = {
     title: 'Example video',
     description: 'This is an example video',
@@ -13,7 +14,7 @@ export function createVideoReferencingChannelFixture(api: QueryNodeApi): CreateV
     category: { existing: { name: 'Education' } },
     // We use the same "existing" syntax to reference a channel by unique property (handle)
     // In this case it's a channel that we created in createChannel example
-    channel: { existing: { handle: 'Example channel' } },
+    channel: { existing: { handle } },
     media: {
       // We use "new" syntax to sygnalize we want to create a new VideoMedia entity that will be related to this Video entity
       new: {
@@ -42,8 +43,65 @@ export function createVideoReferencingChannelFixture(api: QueryNodeApi): CreateV
   return new CreateVideoFixture(api, videoEntity)
 }
 
+function assertVideoMatchQueriedResult(queriedVideo: any, video: VideoEntity) {
+  assert.equal(queriedVideo.title, video.title, 'Should be equal')
+  assert.equal(queriedVideo.description, video.description, 'Should be equal')
+  assert.equal(queriedVideo.duration, video.duration, 'Should be equal')
+  assert.equal(queriedVideo.thumbnailUrl, video.thumbnailUrl, 'Should be equal')
+  assert.equal(queriedVideo.isExplicit, video.isExplicit, 'Should be equal')
+  assert.equal(queriedVideo.isPublic, video.isPublic, 'Should be equal')
+}
+
 export default async function createVideo(api: QueryNodeApi) {
-  const createVideoHappyCaseFixture = createVideoReferencingChannelFixture(api)
+  const channelTitle = 'New channel example'
+  const createVideoHappyCaseFixture = createVideoReferencingChannelFixture(api, channelTitle)
 
   await createVideoHappyCaseFixture.runner(false)
+
+  // Temporary solution (wait 2 minutes)
+  await Utils.wait(120000)
+
+  // Perform number of full text searches on Channel title, that is a slight variation on title that one expects would return the video.
+  let channelFullTextSearchResult = await api.performFullTextSearchOnChannelTitle('video')
+
+  assert(channelFullTextSearchResult.data.search.length === 1, 'Should contain exactly one entry')
+
+  // Both channel and video title starts with `Example`
+  channelFullTextSearchResult = await api.performFullTextSearchOnChannelTitle('Example')
+
+  assert(channelFullTextSearchResult.data.search.length === 2, 'Should contain two entries')
+
+  // Perform number full text searches on Channel title, that absolutely should NOT return the video.
+  channelFullTextSearchResult = await api.performFullTextSearchOnChannelTitle('First')
+
+  assert(channelFullTextSearchResult.data.search.length === 0, 'Should be empty')
+
+  channelFullTextSearchResult = await api.performFullTextSearchOnChannelTitle('vid')
+
+  assert(channelFullTextSearchResult.data.search.length === 0, 'Should be empty')
+
+  // Ensure channel contains only one video with right data
+  const channelResult = await api.getChannelbyHandle(channelTitle)
+
+  assert(channelResult.data.channels[0].videos.length === 1, 'Given channel should contain exactly one video')
+
+  assertVideoMatchQueriedResult(channelResult.data.channels[0].videos[0], createVideoHappyCaseFixture.videoEntity)
+
+  // Perform number of full text searches on Video title, that is a slight variation on title that one expects would return the video.
+  let videoFullTextSearchResult = await api.performFullTextSearchOnVideoTitle('Example')
+
+  assert(videoFullTextSearchResult.data.search.length === 2, 'Should contain two entries')
+
+  videoFullTextSearchResult = await api.performFullTextSearchOnVideoTitle('Example video')
+
+  assert(videoFullTextSearchResult.data.search.length === 1, 'Should contain exactly one video')
+
+  // Perform number full text searches on Video title, that absolutely should NOT return the video.
+  videoFullTextSearchResult = await api.performFullTextSearchOnVideoTitle('unknown')
+
+  assert(videoFullTextSearchResult.data.search.length === 0, 'Should be empty')
+
+  videoFullTextSearchResult = await api.performFullTextSearchOnVideoTitle('MediaVideo')
+
+  assert(videoFullTextSearchResult.data.search.length === 0, 'Should be empty')
 }

+ 30 - 6
tests/network-tests/src/flows/contentDirectory/updatingChannel.ts

@@ -1,21 +1,45 @@
-import { QueryNodeApi, WorkingGroups } from '../../Api'
+import { QueryNodeApi } from '../../Api'
 import { UpdateChannelFixture } from '../../fixtures/contentDirectoryModule'
 import { ChannelEntity } from '@joystream/cd-schemas/types/entities/ChannelEntity'
 import { assert } from 'chai'
+import { Utils } from '../../utils'
 
-export function createUpdateChannelHandleFixture(api: QueryNodeApi): UpdateChannelFixture {
+export function createUpdateChannelHandleFixture(
+  api: QueryNodeApi,
+  handle: string,
+  description: string
+): UpdateChannelFixture {
   // Create partial channel entity, only containing the fields we wish to update
   const channelUpdateInput: Partial<ChannelEntity> = {
-    handle: 'Updated channel handle',
+    description,
   }
 
-  const uniquePropVal: Record<string, any> = { handle: 'Example channel' }
+  const uniquePropVal: Record<string, any> = { handle }
 
   return new UpdateChannelFixture(api, channelUpdateInput, uniquePropVal)
 }
 
 export default async function updateChannel(api: QueryNodeApi) {
-  const createVideoHappyCaseFixture = createUpdateChannelHandleFixture(api)
+  const handle = 'New channel example'
+  const channelResult = await api.getChannelbyHandle(handle)
+  const channel = channelResult.data.channels[0]
 
-  await createVideoHappyCaseFixture.runner(false)
+  const description = 'Updated description'
+  const createUpdateChannelDescriptionHappyCaseFixture = createUpdateChannelHandleFixture(api, handle, description)
+
+  await createUpdateChannelDescriptionHappyCaseFixture.runner(false)
+
+  // Temporary solution (wait 2 minutes)
+  await Utils.wait(120000)
+
+  const channelAfterUpdateResult = await api.getChannelbyHandle(handle)
+  const channelAfterUpdate = channelAfterUpdateResult.data.channels[0]
+
+  // description field should be updated to provided one
+  assert.equal(channelAfterUpdate.description, description, 'Should be equal')
+
+  assert.equal(channelAfterUpdate.handle, channel.handle, 'Should be equal')
+  assert.equal(channelAfterUpdate.coverPhotoUrl, channel.coverPhotoUrl, 'Should be equal')
+  assert.equal(channelAfterUpdate.avatarPhotoUrl, channel.avatarPhotoUrl, 'Should be equal')
+  assert.equal(channelAfterUpdate.isPublic, channel.isPublic, 'Should be equal')
 }

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

@@ -17,11 +17,12 @@ 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 || 'http://127.0.0.1:8080/graphql'
+  const queryNodeUrl: string = env.QUERY_NODE_URL || 'http://127.0.0.1:8081/graphql'
 
   const queryNodeProvider = new ApolloClient({
     uri: queryNodeUrl,
     cache: new InMemoryCache(),
+    defaultOptions: { query: { fetchPolicy: 'no-cache', errorPolicy: 'all' } },
   })
 
   const api: QueryNodeApi = await QueryNodeApi.new(