|
| 1 | +import path from "path"; |
1 | 2 | import { describe, expect, test } from "vitest";
|
2 |
| -import { MergedQualityDefinitionResource } from "./__generated__/mergedTypes"; |
3 |
| -import { doAllQualitiesExist, isOrderOfQualitiesEqual, mapQualities } from "./quality-profiles"; |
4 |
| -import { ConfigQualityProfile, ConfigQualityProfileItem } from "./types/config.types"; |
| 3 | +import { MergedCustomFormatResource, MergedQualityDefinitionResource, MergedQualityProfileResource } from "./__generated__/mergedTypes"; |
| 4 | +import { calculateQualityProfilesDiff, doAllQualitiesExist, isOrderOfQualitiesEqual, mapQualities } from "./quality-profiles"; |
| 5 | +import { CFProcessing } from "./types/common.types"; |
| 6 | +import { ConfigQualityProfile, ConfigQualityProfileItem, MergedConfigInstance } from "./types/config.types"; |
| 7 | +import { cloneWithJSON, loadJsonFile } from "./util"; |
5 | 8 |
|
6 | 9 | describe("QualityProfiles", async () => {
|
| 10 | + const sampleQualityProfile = loadJsonFile<MergedQualityProfileResource>( |
| 11 | + path.resolve(__dirname, `../tests/samples/single_quality_profile.json`), |
| 12 | + ); |
| 13 | + |
| 14 | + const sampleQualityDefinitions = loadJsonFile<MergedQualityDefinitionResource[]>( |
| 15 | + path.resolve(__dirname, `../tests/samples/qualityDefinition.json`), |
| 16 | + ); |
| 17 | + |
| 18 | + const sampleCustomFormat = loadJsonFile<MergedCustomFormatResource>( |
| 19 | + path.resolve(__dirname, `../tests/samples/single_custom_format.json`), |
| 20 | + ); |
| 21 | + |
7 | 22 | test("doAllQualitiesExist - all exist", async ({}) => {
|
8 | 23 | const fromConfig: ConfigQualityProfileItem[] = [
|
9 | 24 | { name: "WEB 1080p", qualities: ["WEBDL-1080p", "WEBRip-1080p"] },
|
@@ -184,12 +199,111 @@ describe("QualityProfiles", async () => {
|
184 | 199 | expect(result[2]!.allowed).toBe(true);
|
185 | 200 | });
|
186 | 201 |
|
187 |
| - test("calculateQualityProfilesDiff - should diff if minUpgradeFormatScore is different", async ({}) => { |
188 |
| - // TODO |
| 202 | + test("calculateQualityProfilesDiff - should diff if minUpgradeFormatScore / minFormatScore is different", async ({}) => { |
| 203 | + const cfMap: CFProcessing = { carrIdMapping: new Map(), cfNameToCarrConfig: new Map() }; |
| 204 | + |
| 205 | + const fromConfig: ConfigQualityProfileItem[] = [{ name: "HDTV-1080p", enabled: false }]; |
| 206 | + |
| 207 | + const resources: MergedQualityDefinitionResource[] = [ |
| 208 | + { id: 1, title: "HDTV-1080p", weight: 2, quality: { id: 1, name: "HDTV-1080p" } }, |
| 209 | + ]; |
| 210 | + |
| 211 | + const profile: ConfigQualityProfile = { |
| 212 | + name: "hi", |
| 213 | + min_format_score: 2, |
| 214 | + qualities: fromConfig, |
| 215 | + quality_sort: "sort", |
| 216 | + upgrade: { allowed: true, until_quality: "HDTV-1080p", until_score: 1000 }, |
| 217 | + score_set: "default", |
| 218 | + }; |
| 219 | + |
| 220 | + const config: MergedConfigInstance = { |
| 221 | + custom_formats: [], |
| 222 | + quality_profiles: [profile], |
| 223 | + customFormatDefinitions: [], |
| 224 | + media_management: {}, |
| 225 | + media_naming: {}, |
| 226 | + }; |
| 227 | + |
| 228 | + const serverProfile = cloneWithJSON(sampleQualityProfile); |
| 229 | + serverProfile.name = "hi"; |
| 230 | + serverProfile.formatItems = []; |
| 231 | + serverProfile.minUpgradeFormatScore = 3; |
| 232 | + serverProfile.minFormatScore = 3; |
| 233 | + serverProfile.cutoff = 1; |
| 234 | + serverProfile.items = [{ allowed: false, items: [], quality: { id: 1, name: "HDTV-1080p" } }]; |
| 235 | + |
| 236 | + const serverQP: MergedQualityProfileResource[] = [serverProfile]; |
| 237 | + const serverQD: MergedQualityDefinitionResource[] = resources; |
| 238 | + const serverCF: MergedCustomFormatResource[] = [cloneWithJSON(sampleCustomFormat)]; |
| 239 | + |
| 240 | + let diff = await calculateQualityProfilesDiff(cfMap, config, serverQP, serverQD, serverCF); |
| 241 | + expect(diff.changedQPs.length).toBe(1); |
| 242 | + expect(diff.create.length).toBe(0); |
| 243 | + expect(diff.noChanges.length).toBe(0); |
| 244 | + |
| 245 | + serverProfile.minFormatScore = 0; |
| 246 | + diff = await calculateQualityProfilesDiff(cfMap, config, serverQP, serverQD, serverCF); |
| 247 | + expect(diff.changedQPs.length).toBe(1); |
| 248 | + expect(diff.create.length).toBe(0); |
| 249 | + expect(diff.noChanges.length).toBe(0); |
| 250 | + |
| 251 | + serverProfile.minUpgradeFormatScore = 0; |
| 252 | + diff = await calculateQualityProfilesDiff(cfMap, config, serverQP, serverQD, serverCF); |
| 253 | + expect(diff.changedQPs.length).toBe(1); |
| 254 | + expect(diff.create.length).toBe(0); |
| 255 | + expect(diff.noChanges.length).toBe(0); |
| 256 | + |
| 257 | + profile.min_format_score = 0; |
| 258 | + serverProfile.minFormatScore = 1; |
| 259 | + diff = await calculateQualityProfilesDiff(cfMap, config, serverQP, serverQD, serverCF); |
| 260 | + expect(diff.changedQPs.length).toBe(1); |
| 261 | + expect(diff.create.length).toBe(0); |
| 262 | + expect(diff.noChanges.length).toBe(0); |
189 | 263 | });
|
190 | 264 |
|
191 |
| - test("calculateQualityProfilesDiff - should not diff if minUpgradeFormatScore is equal", async ({}) => { |
192 |
| - // TODO |
| 265 | + test("calculateQualityProfilesDiff - should not diff if minFormatScore is equal", async ({}) => { |
| 266 | + const cfMap: CFProcessing = { carrIdMapping: new Map(), cfNameToCarrConfig: new Map() }; |
| 267 | + |
| 268 | + const fromConfig: ConfigQualityProfileItem[] = [{ name: "HDTV-1080p", enabled: false }]; |
| 269 | + |
| 270 | + const resources: MergedQualityDefinitionResource[] = [ |
| 271 | + { id: 1, title: "HDTV-1080p", weight: 2, quality: { id: 1, name: "HDTV-1080p" } }, |
| 272 | + ]; |
| 273 | + |
| 274 | + const profile: ConfigQualityProfile = { |
| 275 | + name: "hi", |
| 276 | + min_format_score: 2, |
| 277 | + qualities: fromConfig, |
| 278 | + quality_sort: "sort", |
| 279 | + upgrade: { allowed: true, until_quality: "HDTV-1080p", until_score: 1000 }, |
| 280 | + score_set: "default", |
| 281 | + }; |
| 282 | + |
| 283 | + const config: MergedConfigInstance = { |
| 284 | + custom_formats: [], |
| 285 | + quality_profiles: [profile], |
| 286 | + customFormatDefinitions: [], |
| 287 | + media_management: {}, |
| 288 | + media_naming: {}, |
| 289 | + }; |
| 290 | + |
| 291 | + const serverProfile = cloneWithJSON(sampleQualityProfile); |
| 292 | + serverProfile.name = "hi"; |
| 293 | + serverProfile.formatItems = []; |
| 294 | + serverProfile.minUpgradeFormatScore = 3; |
| 295 | + serverProfile.minFormatScore = 2; |
| 296 | + serverProfile.cutoff = 1; |
| 297 | + serverProfile.items = [{ allowed: false, items: [], quality: { id: 1, name: "HDTV-1080p" } }]; |
| 298 | + |
| 299 | + const serverQP: MergedQualityProfileResource[] = [serverProfile]; |
| 300 | + const serverQD: MergedQualityDefinitionResource[] = resources; |
| 301 | + const serverCF: MergedCustomFormatResource[] = [cloneWithJSON(sampleCustomFormat)]; |
| 302 | + |
| 303 | + const diff = await calculateQualityProfilesDiff(cfMap, config, serverQP, serverQD, serverCF); |
| 304 | + expect(diff.changedQPs.length).toBe(0); |
| 305 | + expect(diff.create.length).toBe(0); |
| 306 | + expect(diff.noChanges.length).toBe(1); |
193 | 307 | });
|
194 | 308 |
|
195 | 309 | test("calculateQualityProfilesDiff - should not diff if minUpgradeFormatScore is not configured", async ({}) => {
|
|
0 commit comments