Skip to content

Commit 2b9350a

Browse files
committed
typescript pre release
1 parent b1934fb commit 2b9350a

7 files changed

Lines changed: 50 additions & 45 deletions

File tree

.github/workflows/pr-tests.yaml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@ name: Run tests on pull request
22
on:
33
pull_request:
44
branches:
5-
main
5+
- main
66

77
jobs:
88
test:
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: Checkout code
1212
uses: actions/checkout@v3
13-
- name: Set up Node.js
14-
uses: actions/setup-node@v3
13+
14+
- name: Install Bun
15+
uses: oven-sh/setup-bun@v1
1516
with:
16-
node-version: "20"
17-
- name: Install dependencies
18-
run: npm install
19-
- name: Run tests
20-
run: npm test
17+
bun-version: latest
18+
19+
- name: Install dependencies with Bun
20+
run: bun install
21+
22+
- name: Run tests with Bun
23+
run: bun test

.github/workflows/publish-image.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77

88
jobs:
99
publish_image:
10+
if: github.event.release.prerelease == false
1011
runs-on: ubuntu-latest
1112
steps:
1213
- name: checkout

filters.test.js

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const { findInstances } = require("./src/services/filter")
2-
const assert = require("assert")
1+
import { findInstances } from "./src/services/filter"
2+
import { strictEqual } from "assert"
33

44
// Moving test data from testData.js directly into this file
55
const movieWebhook = {
@@ -372,7 +372,7 @@ describe("Filter Matching Tests", () => {
372372
},
373373
]
374374
const result = findInstances(movieWebhook, movieGladiator2Data, simpleFilter)
375-
assert.strictEqual(result, "simple-test", "Expected filter to match for 'en' language")
375+
strictEqual(result, "simple-test", "Expected filter to match for 'en' language")
376376
})
377377

378378
it("Exclude movie with keyword", () => {
@@ -388,7 +388,7 @@ describe("Filter Matching Tests", () => {
388388
},
389389
]
390390
const result = findInstances(movieWebhook, data, excludeFilter)
391-
assert.strictEqual(result, null, "Expected filter to exclude due to 'anime' keyword")
391+
strictEqual(result, null, "Expected filter to exclude due to 'anime' keyword")
392392
})
393393

394394
it("Match show with language only", () => {
@@ -403,7 +403,7 @@ describe("Filter Matching Tests", () => {
403403
},
404404
]
405405
const result = findInstances(showWebhook, showArcaneData, simpleFilter)
406-
assert.strictEqual(result, "tv-test", "Expected filter to match for 'en' language")
406+
strictEqual(result, "tv-test", "Expected filter to match for 'en' language")
407407
})
408408

409409
it("Test keyword exclusion", () => {
@@ -423,7 +423,7 @@ describe("Filter Matching Tests", () => {
423423
keywords: [{ id: 321464, name: "intense" }],
424424
}
425425
const result = findInstances(showWebhook, data, excludeFilter)
426-
assert.strictEqual(result, null, "Expected filter to exclude due to 'intense' keyword")
426+
strictEqual(result, null, "Expected filter to exclude due to 'intense' keyword")
427427
})
428428

429429
it("Test keyword matching", () => {
@@ -443,7 +443,7 @@ describe("Filter Matching Tests", () => {
443443
}
444444
const result = findInstances(showWebhook, data, keywordFilter)
445445
// The test logs show this actually matches
446-
assert.strictEqual(result, "keyword-test", "Expected match with simple keyword condition")
446+
strictEqual(result, "keyword-test", "Expected match with simple keyword condition")
447447
})
448448

449449
it("Match movie based on age rating", () => {
@@ -465,13 +465,13 @@ describe("Filter Matching Tests", () => {
465465
originalLanguage: "jp",
466466
}
467467
const result = findInstances(movieWebhook, data, sampleFilters)
468-
assert.strictEqual(result, "radarr3", "Expected filter to match for '16' content rating")
468+
strictEqual(result, "radarr3", "Expected filter to match for '16' content rating")
469469
})
470470

471471
it("Handle non-matching cases gracefully", () => {
472472
const data = { ...movieGladiator2Data, originalLanguage: "fr" }
473473
const result = findInstances(movieWebhook, data, sampleFilters)
474-
assert.strictEqual(result, null, "Expected no filter match due to non-matching language")
474+
strictEqual(result, null, "Expected no filter match due to non-matching language")
475475
})
476476

477477
it("Match a complex filter with mixed types (strings, arrays)", () => {
@@ -488,7 +488,7 @@ describe("Filter Matching Tests", () => {
488488
],
489489
}
490490
const result = findInstances(showWebhook, data, sampleFilters)
491-
assert.strictEqual(result, "sonarr2", "Expected filter to match for mixed types with genres and keywords")
491+
strictEqual(result, "sonarr2", "Expected filter to match for mixed types with genres and keywords")
492492
})
493493

494494
// New tests for require, include, and exclude functionality
@@ -502,7 +502,7 @@ describe("Filter Matching Tests", () => {
502502
genres: [{ id: 12, name: "Adventure" }], // Missing Action genre
503503
}
504504
const result = findInstances(movieWebhook, data, additionalFilters)
505-
assert.strictEqual(result, null, "Expected no match when required genre is missing")
505+
strictEqual(result, null, "Expected no match when required genre is missing")
506506
})
507507

508508
it("Test exclude condition with excluded keyword present", () => {
@@ -514,7 +514,7 @@ describe("Filter Matching Tests", () => {
514514
],
515515
}
516516
const result = findInstances(movieWebhook, data, additionalFilters)
517-
assert.strictEqual(result, null, "Expected no match when excluded keyword is present")
517+
strictEqual(result, null, "Expected no match when excluded keyword is present")
518518
})
519519

520520
it("Test include condition with partial match", () => {
@@ -529,7 +529,7 @@ describe("Filter Matching Tests", () => {
529529
},
530530
]
531531
const result = findInstances(movieWebhook, movieGladiator2Data, includeFilter)
532-
assert.strictEqual(result, "include-test", "Expected match with included keyword")
532+
strictEqual(result, "include-test", "Expected match with included keyword")
533533
})
534534

535535
// Based on the test results, it seems the require condition is not working as expected
@@ -548,7 +548,7 @@ describe("Filter Matching Tests", () => {
548548
]
549549
const result = findInstances(movieWebhook, movieGladiator2Data, simpleFilter)
550550
// The test logs show this doesn't match, so let's expect null
551-
assert.strictEqual(result, null, "Expected no match with simple genre condition")
551+
strictEqual(result, null, "Expected no match with simple genre condition")
552552
})
553553

554554
it("Test array condition", () => {
@@ -564,7 +564,7 @@ describe("Filter Matching Tests", () => {
564564
]
565565
const result = findInstances(movieWebhook, movieGladiator2Data, arrayFilter)
566566
// The test logs show this actually matches
567-
assert.strictEqual(result, "array-test", "Expected match with array genre condition")
567+
strictEqual(result, "array-test", "Expected match with array genre condition")
568568
})
569569

570570
it("Test object condition with include", () => {
@@ -580,7 +580,7 @@ describe("Filter Matching Tests", () => {
580580
]
581581
const result = findInstances(movieWebhook, movieGladiator2Data, includeFilter)
582582
// The test logs show this doesn't match, so let's expect null
583-
assert.strictEqual(result, null, "Expected no match with include genre condition")
583+
strictEqual(result, null, "Expected no match with include genre condition")
584584
})
585585

586586
// Additional tests for require, include, and exclude
@@ -595,11 +595,7 @@ describe("Filter Matching Tests", () => {
595595
},
596596
]
597597
const result = findInstances(movieWebhook, movieGladiator2Data, multiExcludeFilter)
598-
assert.strictEqual(
599-
result,
600-
"multi-exclude-test",
601-
"Expected match when multiple excluded keywords are not present"
602-
)
598+
strictEqual(result, "multi-exclude-test", "Expected match when multiple excluded keywords are not present")
603599
})
604600

605601
it("Test exclude with one matching condition", () => {
@@ -613,7 +609,7 @@ describe("Filter Matching Tests", () => {
613609
},
614610
]
615611
const result = findInstances(movieWebhook, movieGladiator2Data, excludeFilter)
616-
assert.strictEqual(result, null, "Expected no match when one excluded keyword is present")
612+
strictEqual(result, null, "Expected no match when one excluded keyword is present")
617613
})
618614

619615
// Tests for combinations of include, require, and exclude in a single condition
@@ -633,7 +629,7 @@ describe("Filter Matching Tests", () => {
633629
]
634630
const result = findInstances(movieWebhook, movieGladiator2Data, combinedFilter)
635631
// The test logs show this actually matches
636-
assert.strictEqual(result, "combined-keywords-test", "Expected match for combined condition types")
632+
strictEqual(result, "combined-keywords-test", "Expected match for combined condition types")
637633
})
638634

639635
it("Test multiple condition types across different fields", () => {
@@ -650,7 +646,7 @@ describe("Filter Matching Tests", () => {
650646
]
651647
const result = findInstances(movieWebhook, movieGladiator2Data, multiFieldFilter)
652648
// Based on the implementation, we need to check the actual behavior
653-
assert.strictEqual(result, null, "Expected behavior for multiple condition types across fields")
649+
strictEqual(result, null, "Expected behavior for multiple condition types across fields")
654650
})
655651

656652
it("Test complex condition with all types", () => {
@@ -681,7 +677,7 @@ describe("Filter Matching Tests", () => {
681677

682678
const result = findInstances(movieWebhook, complexData, complexFilter)
683679
// Based on the logs, this doesn't match due to the require condition
684-
assert.strictEqual(result, null, "Expected no match for complex condition with all types")
680+
strictEqual(result, null, "Expected no match for complex condition with all types")
685681
})
686682

687683
it("Test complex condition with negative case", () => {
@@ -712,7 +708,7 @@ describe("Filter Matching Tests", () => {
712708

713709
const result = findInstances(movieWebhook, complexData, complexFilter)
714710
// This should not match due to the excluded keyword
715-
assert.strictEqual(result, null, "Expected no match when excluded keyword is present")
711+
strictEqual(result, null, "Expected no match when excluded keyword is present")
716712
})
717713
})
718714
})

src/api/overseerr.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export const testConnection = async (): Promise<void> => {
3838
else if (typeof error === "string") errorMessage = error
3939

4040
logger.error(`Could not reach Overseerr: ${errorMessage}`)
41-
process.exit(1)
4241
}
4342
}
4443

@@ -53,7 +52,7 @@ export const approveRequest = async (requestId: string): Promise<void> => {
5352
if (!response.ok) {
5453
throw new Error(`${response.status} ${response.statusText}`)
5554
}
56-
55+
5756
logger.info(`Request ID ${requestId} approved successfully`)
5857
} catch (error) {
5958
logger.error(`Error approving request: ${error}`)
@@ -75,7 +74,7 @@ export const applyConfig = async (requestId: string, postData: Record<string, an
7574
if (!response.ok) {
7675
throw new Error(`${response.status} ${response.statusText}`)
7776
}
78-
77+
7978
logger.info(`Configuration applied to request ID ${requestId}`)
8079
} catch (error) {
8180
logger.error(`Error applying configuration: ${error}`)

src/config/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { Config } from "../types"
66

77
const ajv = new Ajv({ allErrors: true })
88

9-
const yamlFilePath = process.argv[3] || "../config.yaml"
9+
const yamlFilePath = process.argv[3] || "./config.yaml"
1010

1111
const schema: Schema = {
1212
$schema: "http://json-schema.org/draft-07/schema#",
@@ -57,9 +57,6 @@ const schema: Schema = {
5757
type: "string",
5858
enum: ["movie", "tv"],
5959
},
60-
is_not_4k: {
61-
type: "boolean",
62-
},
6360
is_4k: {
6461
type: "boolean",
6562
},
@@ -93,6 +90,16 @@ const schema: Schema = {
9390
required: ["require"],
9491
additionalProperties: false,
9592
},
93+
{
94+
type: "object",
95+
properties: {
96+
include: {
97+
anyOf: [{ type: "string" }, { type: "array", items: { type: "string" } }],
98+
},
99+
},
100+
required: ["include"],
101+
additionalProperties: false,
102+
},
96103
],
97104
},
98105
},

src/services/filter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,11 @@ export const matchContentRatings = (contentRatings: ContentRatings, filterCondit
207207
*/
208208
export const findInstances = (webhook: Webhook, data: MediaData, filters: Filter[]): string | string[] | null => {
209209
try {
210-
const matchingFilter = filters.find(({ media_type, is_not_4k, is_4k, conditions }) => {
210+
const matchingFilter = filters.find(({ media_type, is_4k, conditions }) => {
211211
// Quick checks first
212212
if (media_type !== webhook.media.media_type) return false
213-
if (is_not_4k && webhook.media.status !== "PENDING") return false
214-
if (is_4k && webhook.media.status4k !== "PENDING") return false
213+
if (is_4k === false && webhook.media.status !== "PENDING") return false
214+
if (is_4k === true && webhook.media.status4k !== "PENDING") return false
215215

216216
// If no conditions, it's a match
217217
if (!conditions || Object.keys(conditions).length === 0) return true

src/types/config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ interface FilterCondition {
1212

1313
export interface Filter {
1414
media_type: "movie" | "tv"
15-
is_not_4k?: boolean
1615
is_4k?: boolean
1716
conditions?: FilterCondition
1817
apply: string | string[]

0 commit comments

Comments
 (0)