-
Notifications
You must be signed in to change notification settings - Fork 4
add tests for HTTP APIs and their routes #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
akhileshthite
wants to merge
14
commits into
main
Choose a base branch
from
api-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
124cbcc
test: add tests for HTTP APIs and their routes
akhileshthite fcf7ffd
refactor: improved reliability and simplification for admins.test.ts
akhileshthite f3b5a9e
chore: add a TODO for testing of APS's admin API interactions
akhileshthite 1fa68c6
test: add tests for creation APIs
akhileshthite 7d0b35c
test: add tests for followers APIs
akhileshthite 2754fe4
test: add tests for inbox APIs
akhileshthite 35d1fd1
test: add tests for outbox APIs
akhileshthite 1f345bb
test: add tests for hooks APIs
akhileshthite 7e34a68
test: add tests for blockallowlist APIs
akhileshthite f7831b0
Merge branch 'main' into api-tests
16de91f
Use same node version as mauve for tests
d8119ec
feat: validate admin list updates in admins.test.ts
akhileshthite c4a6593
test: ensure blocklist and allowlist routes correctly handle and retu…
akhileshthite 3720549
Merge branch 'main' into api-tests
RangerMauve File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import anyTest, { TestFn } from 'ava' | ||
| import sinon from 'sinon' | ||
| import { spawnTestServer } from '../fixtures/spawnServer.js' | ||
| import { FastifyTypebox } from './index.js' | ||
| import ActivityPubSystem from '../apsystem.js' | ||
|
|
||
| interface TestContext { | ||
| server: FastifyTypebox | ||
| hasAdminPermissionForRequestStub: sinon.SinonStub | ||
| } | ||
|
|
||
| const test = anyTest as TestFn<TestContext> | ||
|
|
||
| test.beforeEach(async t => { | ||
| t.context.server = await spawnTestServer() | ||
| t.context.hasAdminPermissionForRequestStub = sinon.stub(ActivityPubSystem.prototype, 'hasAdminPermissionForRequest') | ||
| }) | ||
|
|
||
| test.afterEach.always(async t => { | ||
| await t.context.server?.close() | ||
| t.context.hasAdminPermissionForRequestStub.restore() | ||
| }) | ||
|
|
||
| test.serial('GET /admins - success', async t => { | ||
| t.context.hasAdminPermissionForRequestStub.resolves(true) | ||
|
|
||
| const response = await t.context.server.inject({ | ||
| method: 'GET', | ||
| url: '/v1/admins' | ||
| }) | ||
|
|
||
| t.is(response.statusCode, 200, 'returns a status code of 200') | ||
| }) | ||
|
|
||
| test.serial('GET /admins - not allowed', async t => { | ||
| t.context.hasAdminPermissionForRequestStub.resolves(false) | ||
|
|
||
| const response = await t.context.server.inject({ | ||
| method: 'GET', | ||
| url: '/v1/admins' | ||
| }) | ||
|
|
||
| t.is(response.statusCode, 403, 'returns a status code of 403') | ||
| }) | ||
|
|
||
| test.serial('POST /admins - add admins', async t => { | ||
| t.context.hasAdminPermissionForRequestStub.resolves(true) | ||
|
|
||
| // Add a new admin | ||
| await t.context.server.inject({ | ||
| method: 'POST', | ||
| url: '/v1/admins', | ||
| payload: 'newadmin@example.com', | ||
| headers: { 'Content-Type': 'text/plain' } | ||
| }) | ||
|
|
||
| // Fetch the list of admins to verify the addition | ||
| const response = await t.context.server.inject({ | ||
| method: 'GET', | ||
| url: '/v1/admins' | ||
| }) | ||
|
|
||
| t.is(response.statusCode, 200, 'returns a status code of 200 after adding admin') | ||
| t.deepEqual(response.body.split('\n'), ['newadmin@example.com'], 'Admin list should contain only the new admin') | ||
| }) | ||
|
|
||
| test.serial('POST /admins - not allowed', async t => { | ||
| t.context.hasAdminPermissionForRequestStub.resolves(false) | ||
|
|
||
| const response = await t.context.server.inject({ | ||
| method: 'POST', | ||
| url: '/v1/admins', | ||
| payload: 'newadmin@example.com', | ||
| headers: { 'Content-Type': 'text/plain' } | ||
| }) | ||
|
|
||
| t.is(response.statusCode, 403, 'returns a status code of 403') | ||
| }) | ||
|
|
||
| test.serial('DELETE /admins - remove admins', async t => { | ||
| t.context.hasAdminPermissionForRequestStub.resolves(true) | ||
|
|
||
| // Remove an admin | ||
| await t.context.server.inject({ | ||
| method: 'DELETE', | ||
| url: '/v1/admins', | ||
| payload: 'removeadmin@example.com', | ||
| headers: { 'Content-Type': 'text/plain' } | ||
| }) | ||
|
|
||
| // Fetch the list of admins to verify the removal | ||
| const response = await t.context.server.inject({ | ||
| method: 'GET', | ||
| url: '/v1/admins' | ||
| }) | ||
|
|
||
| t.is(response.statusCode, 200, 'returns a status code of 200 after removing admin') | ||
|
|
||
| // Filter out empty strings from the response body | ||
| const adminList = response.body.split('\n').filter(admin => admin.trim() !== '') | ||
| t.deepEqual(adminList, [], 'Admin list should be empty after removal') | ||
| }) | ||
|
|
||
| test.serial('DELETE /admins - not allowed', async t => { | ||
| t.context.hasAdminPermissionForRequestStub.resolves(false) | ||
|
|
||
| const response = await t.context.server.inject({ | ||
| method: 'DELETE', | ||
| url: '/v1/admins', | ||
| payload: 'removeadmin@example.com' | ||
| }) | ||
|
|
||
| t.is(response.statusCode, 403, 'returns a status code of 403') | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.