Browse Source

Content directory & query node integration tests: Add Full text search on Video titles

iorveth 4 years ago
parent
commit
75673a9d8b

+ 29 - 2
tests/network-tests/src/Api.ts

@@ -2045,7 +2045,14 @@ export class QueryNodeApi extends Api {
           avatarPhotoUrl
           isPublic
           isCurated
-          language
+          videos {
+            title
+            description
+            duration
+            thumbnailUrl
+            isExplicit
+            isPublic
+          }
         }
       }
     `
@@ -2065,7 +2072,6 @@ export class QueryNodeApi extends Api {
               avatarPhotoUrl
               isPublic
               isCurated
-              language
             }
           }
         }
@@ -2074,4 +2080,25 @@ export class QueryNodeApi extends Api {
 
     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!) {
+        titles(text: $text) {
+          item {
+            ... on Video {
+              title
+              description
+              duration
+              thumbnailUrl
+              isExplicit
+              isPublic
+            }
+          }
+        }
+      }
+    `
+
+    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

+ 0 - 22
tests/network-tests/src/flows/contentDirectory/creatingChannel.ts

@@ -39,27 +39,5 @@ export default async function channelCreation(api: QueryNodeApi) {
   // Ensure newly created channel was parsed by query node
   let result = await api.getChannelbyTitle(createChannelHappyCaseFixture.channelEntity.title)
 
-  console.log(result.data.channels[0])
-
   assertChannelMatchQueriedResult(result.data.channels[0], createChannelHappyCaseFixture.channelEntity)
-
-  // Perform number of full text searches on Channel title, that should return a Channel.
-  result = await api.performFullTextSearchOnChannelTitle('Examp')
-
-  console.log(result.data.titles[0].item)
-
-  assertChannelMatchQueriedResult(result.data.titles[0].item, createChannelHappyCaseFixture.channelEntity)
-
-  result = await api.performFullTextSearchOnChannelTitle(' channel')
-
-  assertChannelMatchQueriedResult(result.data.titles[0].item, createChannelHappyCaseFixture.channelEntity)
-
-  // Perform number full text searches on Channel title, that should not return a Channel.
-  result = await api.performFullTextSearchOnChannelTitle('First')
-
-  assert(result.data.titles[0].length === 0, 'Should be empty')
-
-  result = await api.performFullTextSearchOnChannelTitle('Chanel')
-
-  assert(result.data.titles[0].length === 0, 'Should be empty')
 }

+ 58 - 5
tests/network-tests/src/flows/contentDirectory/creatingVideo.ts

@@ -2,8 +2,9 @@ import { QueryNodeApi, WorkingGroups } from '../../Api'
 import { CreateVideoFixture } from '../../fixtures/contentDirectoryModule'
 import { VideoEntity } from 'cd-schemas/types/entities/VideoEntity'
 import { assert } from 'chai'
+import { Utils } from '../../utils'
 
-export function createVideoReferencingChannelFixture(api: QueryNodeApi): CreateVideoFixture {
+export function createVideoReferencingChannelFixture(api: QueryNodeApi, title: 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 (title)
     // In this case it's a channel that we created in createChannel example
-    channel: { existing: { title: 'Example channel' } },
+    channel: { existing: { title } },
     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,11 +43,63 @@ export function createVideoReferencingChannelFixture(api: QueryNodeApi): CreateV
   return new CreateVideoFixture(api, videoEntity)
 }
 
+function assertVideoMatchQueriedResult(queriedVideo: any, video: VideoEntity) {
+  assert(queriedVideo.title === video.title, 'Should be equal')
+  assert(queriedVideo.description === video.description, 'Should be equal')
+  assert(queriedVideo.duration === video.duration, 'Should be equal')
+  assert(queriedVideo.thumbnailUrl === video.thumbnailURL, 'Should be equal')
+  assert(queriedVideo.avatarPhotoUrl === video.isExplicit, 'Should be equal')
+  assert(queriedVideo.isPublic === video.isPublic, 'Should be equal')
+}
+
 export default async function createVideo(api: QueryNodeApi) {
-  const createVideoHappyCaseFixture = createVideoReferencingChannelFixture(api)
+  const channelTitle = 'Example channel'
+  const createVideoHappyCaseFixture = createVideoReferencingChannelFixture(api, channelTitle)
+
+  await createVideoHappyCaseFixture.runner(false)
 
   // Temporary solution (wait 2 minutes)
-  // await Utils.wait(120000)
+  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('Examp')
+
+  assert(channelFullTextSearchResult.data.titles[0].item.videos.length === 1, 'Should contain exactly one video')
+
+  channelFullTextSearchResult = await api.performFullTextSearchOnChannelTitle(' channel')
+
+  assert(channelFullTextSearchResult.data.titles[0].item.videos.length === 1, 'Should contain exactly one video')
+
+  // Perform number full text searches on Channel title, that absolutely should NOT return the video.
+  channelFullTextSearchResult = await api.performFullTextSearchOnChannelTitle('First')
+
+  assert(channelFullTextSearchResult.data.titles.length === 0, 'Should be empty')
+
+  channelFullTextSearchResult = await api.performFullTextSearchOnChannelTitle('Chanel')
+
+  assert(channelFullTextSearchResult.data.titles.length === 0, 'Should be empty')
+
+  // Ensure channel contains only one video with right data
+  const channelResult = await api.getChannelbyTitle(channelTitle)
+
+  assertVideoMatchQueriedResult(channelResult.data.channels[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.titles.length === 1, 'Should contain exactly one video')
+
+  videoFullTextSearchResult = await api.performFullTextSearchOnVideoTitle('video')
+
+  assert(videoFullTextSearchResult.data.titles.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.titles.length === 0, 'Should be empty')
+
+  videoFullTextSearchResult = await api.performFullTextSearchOnVideoTitle('MediaVideo')
+
+  assert(videoFullTextSearchResult.data.titles.length === 0, 'Should be empty')
 
-  await createVideoHappyCaseFixture.runner(false)
 }