Skip to content

Commit

Permalink
ci: adjust paths filter for tests, add new test case
Browse files Browse the repository at this point in the history
  • Loading branch information
rocktimsaikia committed Aug 25, 2024
1 parent 3a4c04b commit 69abd24
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ name: Tests
on:
push:
branches: [main]
paths:
- 'server/**/*.ts'
- 'server/test/**'
pull_request:
branches: [main]
paths:
- 'server/**/*.ts'
- 'server/test/**'
paths:
- 'server/**/*.ts'
- 'server/test/**'

jobs:
build:
Expand Down
11 changes: 7 additions & 4 deletions server/test/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ test("Should pass on protected API urls", () => {
expect(isProtectedEndpoint(`${BASE_PATH}quotes?character=naruto`)).toBeTruthy();
expect(isProtectedEndpoint(`${BASE_PATH}quotes/?anime=naruto`)).toBeTruthy();
expect(isProtectedEndpoint(`${BASE_PATH}quotes/?character=naruto`)).toBeTruthy();

// Accepts additional not pre-defined params like `foo` here but only in the presence
// of a premium query param which is `character` in this case below.
expect(isProtectedEndpoint(`${BASE_PATH}quotes/random/?character=naruto&foo=bar`)).toBeTruthy();
});

test("should fail on unprotected/free API urls", () => {
Expand All @@ -36,3 +32,10 @@ test("Should pass on valid protected API urls with additional params", () => {
isProtectedEndpoint(`${BASE_PATH}quotes/random/?character=naruto&anime=naruto&page=2`),
).toBeTruthy();
});

test("Should pass on protected API urls with additional unknown params", () => {
// Accepts additional not pre-defined params like `foo` here but only in the presence
// of a premium query param which is `character` in this case below.
expect(isProtectedEndpoint(`${BASE_PATH}quotes/random/?character=naruto&foo=bar`)).toBeTruthy();
expect(isProtectedEndpoint(`${BASE_PATH}quotes/random/?foo=bar`)).toBeFalsy();
});

0 comments on commit 69abd24

Please sign in to comment.