@@ -13,13 +13,15 @@ describe("getBranding", () => {
13
13
const videoIDEmpty = "videoID4" ;
14
14
const videoIDRandomTime = "videoID5" ;
15
15
const videoIDUnverified = "videoID6" ;
16
+ const videoIDvidDuration = "videoID7" ;
16
17
17
18
const videoID1Hash = getHash ( videoID1 , 1 ) . slice ( 0 , 4 ) ;
18
19
const videoID2LockedHash = getHash ( videoID2Locked , 1 ) . slice ( 0 , 4 ) ;
19
20
const videoID2ShadowHideHash = getHash ( videoID2ShadowHide , 1 ) . slice ( 0 , 4 ) ;
20
21
const videoIDEmptyHash = "aaaa" ;
21
22
const videoIDRandomTimeHash = getHash ( videoIDRandomTime , 1 ) . slice ( 0 , 4 ) ;
22
23
const videoIDUnverifiedHash = getHash ( videoIDUnverified , 1 ) . slice ( 0 , 4 ) ;
24
+ const videoIDvidDurationHash = getHash ( videoIDUnverified , 1 ) . slice ( 0 , 4 ) ;
23
25
24
26
const endpoint = "/api/branding" ;
25
27
const getBranding = ( params : Record < string , any > ) => client ( {
@@ -40,6 +42,7 @@ describe("getBranding", () => {
40
42
const thumbnailQuery = `INSERT INTO "thumbnails" ("videoID", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?)` ;
41
43
const thumbnailTimestampsQuery = `INSERT INTO "thumbnailTimestamps" ("UUID", "timestamp") VALUES (?, ?)` ;
42
44
const thumbnailVotesQuery = `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden", "downvotes", "removed") VALUES (?, ?, ?, ?, ?, ?)` ;
45
+ const segmentQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "service", "videoDuration", "hidden", "shadowHidden", "description", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' ;
43
46
44
47
await Promise . all ( [
45
48
db . prepare ( "run" , titleQuery , [ videoID1 , "title1" , 0 , "userID1" , Service . YouTube , videoID1Hash , 1 , "UUID1" ] ) ,
@@ -107,9 +110,8 @@ describe("getBranding", () => {
107
110
db . prepare ( "run" , thumbnailVotesQuery , [ "UUID32T" , 1 , 0 , 1 , 0 , 0 ] )
108
111
] ) ;
109
112
110
- const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "service", "videoDuration", "hidden", "shadowHidden", "description", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' ;
111
- await db . prepare ( "run" , query , [ videoIDRandomTime , 1 , 11 , 1 , 0 , "uuidbranding1" , "testman" , 0 , 50 , "sponsor" , "skip" , "YouTube" , 100 , 0 , 0 , "" , videoIDRandomTimeHash ] ) ;
112
- await db . prepare ( "run" , query , [ videoIDRandomTime , 20 , 33 , 2 , 0 , "uuidbranding2" , "testman" , 0 , 50 , "intro" , "skip" , "YouTube" , 100 , 0 , 0 , "" , videoIDRandomTimeHash ] ) ;
113
+ await db . prepare ( "run" , segmentQuery , [ videoIDRandomTime , 1 , 11 , 1 , 0 , "uuidbranding1" , "testman" , 0 , 50 , "sponsor" , "skip" , "YouTube" , 100 , 0 , 0 , "" , videoIDRandomTimeHash ] ) ;
114
+ await db . prepare ( "run" , segmentQuery , [ videoIDRandomTime , 20 , 33 , 2 , 0 , "uuidbranding2" , "testman" , 0 , 50 , "intro" , "skip" , "YouTube" , 100 , 0 , 0 , "" , videoIDRandomTimeHash ] ) ;
113
115
114
116
await Promise . all ( [
115
117
db . prepare ( "run" , titleQuery , [ videoIDUnverified , "title1" , 0 , "userID1" , Service . YouTube , videoIDUnverifiedHash , 1 , "UUID-uv-1" ] ) ,
@@ -130,6 +132,17 @@ describe("getBranding", () => {
130
132
db . prepare ( "run" , thumbnailVotesQuery , [ "UUID-uv-2T" , 2 , 0 , 0 , 0 , 0 ] ) ,
131
133
db . prepare ( "run" , thumbnailVotesQuery , [ "UUID-uv-3T" , 1 , 0 , 0 , 0 , 0 ] )
132
134
] ) ;
135
+
136
+ // Video duration test segments
137
+ await Promise . all ( [
138
+ db . prepare ( "run" , segmentQuery , [ videoIDvidDuration , 0 , 1 , 0 , 0 , "uuidvd1" , "testman" , 10 , 0 , "sponsor" , "skip" , "YouTube" , 0 , 0 , 0 , "" , videoIDvidDurationHash ] ) , // visible, no vid duration
139
+ db . prepare ( "run" , segmentQuery , [ videoIDvidDuration , 0 , 2 , - 2 , 0 , "uuidvd2" , "testman" , 11 , 0 , "sponsor" , "skip" , "YouTube" , 10 , 0 , 0 , "" , videoIDvidDurationHash ] ) , // downvoted
140
+ db . prepare ( "run" , segmentQuery , [ videoIDvidDuration , 0 , 3 , 0 , 0 , "uuidvd3" , "testman" , 12 , 0 , "sponsor" , "skip" , "YouTube" , 10.1 , 1 , 0 , "" , videoIDvidDurationHash ] ) , // hidden
141
+ db . prepare ( "run" , segmentQuery , [ videoIDvidDuration , 0 , 4 , 0 , 0 , "uuidvd4" , "testman" , 13 , 0 , "sponsor" , "skip" , "YouTube" , 20.1 , 0 , 1 , "" , videoIDvidDurationHash ] ) , // shadowhidden
142
+ db . prepare ( "run" , segmentQuery , [ videoIDvidDuration , 0 , 5 , 0 , 0 , "uuidvd5" , "testman" , 14 , 0 , "sponsor" , "skip" , "YouTube" , 21.3 , 0 , 0 , "" , videoIDvidDurationHash ] ) , // oldest visible w/ duration, should be picked
143
+ db . prepare ( "run" , segmentQuery , [ videoIDvidDuration , 0 , 6 , 0 , 0 , "uuidvd6" , "testman" , 15 , 0 , "sponsor" , "skip" , "YouTube" , 21.37 , 0 , 0 , "" , videoIDvidDurationHash ] ) , // not the oldest visible
144
+ db . prepare ( "run" , segmentQuery , [ videoIDvidDuration , 0 , 7 , - 2 , 0 , "uuidvd7" , "testman" , 16 , 0 , "sponsor" , "skip" , "YouTube" , 21.38 , 0 , 0 , "" , videoIDvidDurationHash ] ) , // downvoted, not the oldest
145
+ ] ) ;
133
146
} ) ;
134
147
135
148
it ( "should get top titles and thumbnails" , async ( ) => {
@@ -312,6 +325,16 @@ describe("getBranding", () => {
312
325
} ) ;
313
326
} ) ;
314
327
328
+ it ( "should get the correct video duration" , async ( ) => {
329
+ const correctDuration = 21.3 ;
330
+
331
+ const result1 = await getBranding ( { videoID : videoIDvidDuration , fetchAll : true } ) ;
332
+ const result2 = await getBrandingByHash ( videoIDvidDurationHash , { fetchAll : true } ) ;
333
+
334
+ assert . strictEqual ( result1 . data . videoDuration , correctDuration ) ;
335
+ assert . strictEqual ( result2 . data [ videoIDvidDuration ] . videoDuration , correctDuration ) ;
336
+ } ) ;
337
+
315
338
async function checkVideo ( videoID : string , videoIDHash : string , fetchAll : boolean , expected : {
316
339
titles : TitleResult [ ] ,
317
340
thumbnails : ThumbnailResult [ ]
0 commit comments