Browse Source

CreateVideoFixture added

iorveth 4 years ago
parent
commit
98da085f47

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

@@ -1948,7 +1948,6 @@ export class Api {
       },
     ]
   )
-
   return await this.sendContentDirectoryTransaction(memberId, parser)
   }
 
@@ -1964,7 +1963,6 @@ export class Api {
       },
     ]
   )
-  
   return await this.sendContentDirectoryTransaction(memberId, parser)
   }
 

+ 20 - 13
tests/network-tests/src/fixtures/contentDirectoryModule.ts

@@ -6,6 +6,7 @@ import { v4 as uuid } from 'uuid'
 import { Utils } from '../utils'
 import { Fixture } from '../Fixture'
 import { ChannelEntity } from 'cd-schemas/types/entities/ChannelEntity'
+import { VideoEntity } from 'cd-schemas/types/entities/VideoEntity'
 
 export class CreateChannelFixture implements Fixture {
   private api: Api
@@ -28,17 +29,23 @@ export class CreateChannelFixture implements Fixture {
   }
 }
 
-export function createSimpleChannelFixture(api: Api): 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, 0, channelEntity)
+export class CreateVideoFixture implements Fixture {
+  private api: Api
+  private memberId: number
+  private videoEntity: VideoEntity
+
+  public constructor(api: Api, memberId: number, videoEntity: VideoEntity) {
+    this.api = api
+    this.memberId = memberId
+    this.videoEntity = videoEntity
+  }
+
+  public async runner(expectFailure: boolean): Promise<void> {
+    await this.api.createVideoEntity(this.memberId, this.videoEntity)
+
+
+    if (expectFailure) {
+      throw new Error('Successful fixture run while expecting failure')
+    }
+  }
 }

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

@@ -1,5 +1,4 @@
 import { Api, WorkingGroups } from '../../Api'
-import { createSimpleChannelFixture } from '../../fixtures/contentDirectoryModule'
 import { assert } from 'chai'
 import { KeyringPair } from '@polkadot/keyring/types'
 

+ 17 - 1
tests/network-tests/src/flows/contentDirectory/creatingChannel.ts

@@ -1,7 +1,23 @@
 import { Api, WorkingGroups } from '../../Api'
-import { createSimpleChannelFixture } from '../../fixtures/contentDirectoryModule'
+import { CreateChannelFixture } from '../../fixtures/contentDirectoryModule'
+import { ChannelEntity } from 'cd-schemas/types/entities/ChannelEntity'
 import { assert } from 'chai'
 
+export function createSimpleChannelFixture(api: Api): 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, 0, channelEntity)
+}
+
 export default async function channelCreation(api: Api) {
   const createChannelHappyCaseFixture = createSimpleChannelFixture(api)
 

+ 49 - 0
tests/network-tests/src/flows/contentDirectory/creatingVideo.ts

@@ -0,0 +1,49 @@
+import { Api, WorkingGroups } from '../../Api'
+import { CreateVideoFixture } from '../../fixtures/contentDirectoryModule'
+import { VideoEntity } from 'cd-schemas/types/entities/VideoEntity'
+import { assert } from 'chai'
+
+export function createVideoReferencingChannelFixture(api: Api): 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/' } } } },
+        },
+      },
+      // 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, 0, videoEntity)
+}
+
+export default async function createVideo(api: Api) {
+  const createVideoHappyCaseFixture = createVideoReferencingChannelFixture(api)
+ 
+  await createVideoHappyCaseFixture.runner(false)
+}

+ 3 - 0
tests/network-tests/src/scenarios/content-directory.ts

@@ -4,6 +4,7 @@ import { config } from 'dotenv'
 import leaderSetup from '../flows/workingGroup/leaderSetup'
 import initializeContentDirectory from '../flows/contentDirectory/contentDirectoryInitialization'
 import createChannel from '../flows/contentDirectory/creatingChannel'
+import createVideo from '../flows/contentDirectory/creatingVideo'
 
 const scenario = async () => {
   // Load env variables
@@ -24,6 +25,8 @@ const scenario = async () => {
 
   await createChannel(api)
 
+  await createVideo(api)
+  
   // Note: disconnecting and then reconnecting to the chain in the same process
   // doesn't seem to work!
   api.close()