@@ -3,59 +3,43 @@ import { db } from "../../src/databases/databases";
3
3
import { Postgres } from "../../src/databases/Postgres" ;
4
4
import { client } from "../utils/httpClient" ;
5
5
import { partialDeepEquals } from "../utils/partialDeepEquals" ;
6
-
7
- // Only works with Postgres
8
- if ( db instanceof Postgres ) {
9
-
10
- describe ( "getChapterNames" , function ( ) {
11
- const endpoint = "/api/chapterNames" ;
12
-
13
- const chapterNamesVid1 = "chapterNamesVid" ;
14
- const chapterChannelID = "chapterChannelID" ;
15
-
16
- before ( async ( ) => {
17
- const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "service", "videoDuration", "hidden", "shadowHidden", "description") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' ;
18
- await db . prepare ( "run" , query , [ chapterNamesVid1 , 60 , 80 , 2 , 0 , "chapterNamesVid-1" , "testman" , 0 , 50 , "chapter" , "chapter" , "YouTube" , 0 , 0 , 0 , "Weird name" ] ) ;
19
- await db . prepare ( "run" , query , [ chapterNamesVid1 , 70 , 75 , 2 , 0 , "chapterNamesVid-2" , "testman" , 0 , 50 , "chapter" , "chapter" , "YouTube" , 0 , 0 , 0 , "A different one" ] ) ;
20
- await db . prepare ( "run" , query , [ chapterNamesVid1 , 71 , 76 , 2 , 0 , "chapterNamesVid-3" , "testman" , 0 , 50 , "chapter" , "chapter" , "YouTube" , 0 , 0 , 0 , "Something else" ] ) ;
21
-
22
- await db . prepare ( "run" , `INSERT INTO "videoInfo" ("videoID", "channelID", "title", "published")
23
- SELECT ?, ?, ?, ?` , [
24
- chapterNamesVid1 , chapterChannelID , "" , 0
25
- ] ) ;
26
- } ) ;
27
-
28
- it ( "Search for 'weird'" , async ( ) => {
29
- const result = await client . get ( `${ endpoint } ?description=weird&channelID=${ chapterChannelID } ` ) ;
30
- const expected = [ {
31
- description : "Weird name" ,
32
- } ] ;
33
-
34
- assert . strictEqual ( result . status , 200 ) ;
35
- assert . strictEqual ( result . data . length , 3 ) ;
36
- assert . ok ( partialDeepEquals ( result . data , expected ) ) ;
37
- } ) ;
38
-
39
- it ( "Search for 'different'" , async ( ) => {
40
- const result = await client . get ( `${ endpoint } ?description=different&channelID=${ chapterChannelID } ` ) ;
41
- const expected = [ {
42
- description : "A different one" ,
43
- } ] ;
44
-
45
- assert . strictEqual ( result . status , 200 ) ;
46
- assert . strictEqual ( result . data . length , 3 ) ;
47
- assert . ok ( partialDeepEquals ( result . data , expected ) ) ;
48
- } ) ;
49
-
50
- it ( "Search for 'something'" , async ( ) => {
51
- const result = await client . get ( `${ endpoint } ?description=something&channelID=${ chapterChannelID } ` ) ;
52
- const expected = [ {
53
- description : "Something else" ,
54
- } ] ;
55
-
56
- assert . strictEqual ( result . status , 200 ) ;
57
- assert . strictEqual ( result . data . length , 3 ) ;
58
- assert . ok ( partialDeepEquals ( result . data , expected ) ) ;
59
- } ) ;
6
+ import { insertChapter } from "../utils/segmentQueryGen" ;
7
+ import { genRandomValue } from "../utils/getRandom" ;
8
+ import { insertVideoInfo } from "../utils/queryGen" ;
9
+
10
+ describe ( "getChapterNames" , function ( ) {
11
+ const endpoint = "/api/chapterNames" ;
12
+
13
+ const chapterNamesVid1 = genRandomValue ( "video" , "getChapterNames" ) ;
14
+ const chapterChannelID = genRandomValue ( "channel" , "getChapterNames" ) ;
15
+ const chapterNames = [
16
+ "Weird name" ,
17
+ "A different one" ,
18
+ "Something else" ,
19
+ ] ;
20
+
21
+ const nameSearch = ( query : string , expected : string ) : Promise < void > => {
22
+ const expectedData = [ {
23
+ description : expected
24
+ } ] ;
25
+ return client . get ( `${ endpoint } ?description=${ query } &channelID=${ chapterChannelID } ` )
26
+ . then ( res => {
27
+ assert . strictEqual ( res . status , 200 ) ;
28
+ assert . strictEqual ( res . data . length , 1 ) ;
29
+ assert . ok ( partialDeepEquals ( res . data , expectedData ) ) ;
30
+ } ) ;
31
+ } ;
32
+
33
+ before ( async function ( ) {
34
+ if ( ! ( db instanceof Postgres ) ) this . skip ( ) ; // only works with Postgres
35
+ await insertChapter ( db , chapterNames [ 0 ] , { videoID : chapterNamesVid1 , startTime : 60 , endTime : 80 } ) ;
36
+ await insertChapter ( db , chapterNames [ 1 ] , { videoID : chapterNamesVid1 , startTime : 70 , endTime : 75 } ) ;
37
+ await insertChapter ( db , chapterNames [ 2 ] , { videoID : chapterNamesVid1 , startTime : 71 , endTime : 76 } ) ;
38
+
39
+ await insertVideoInfo ( db , chapterNamesVid1 , chapterChannelID ) ;
60
40
} ) ;
61
- }
41
+
42
+ it ( "Search for 'weird'" , ( ) => nameSearch ( "weird" , chapterNames [ 0 ] ) ) ;
43
+ it ( "Search for 'different'" , ( ) => nameSearch ( "different" , chapterNames [ 1 ] ) ) ;
44
+ it ( "Search for 'something'" , ( ) => nameSearch ( "something" , chapterNames [ 2 ] ) ) ;
45
+ } ) ;
0 commit comments