Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion externaldocs.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@
[Github Actions](https://docs.github.com/en/actions)

# Misc
[Dotenv](https://github.com/motdotla/dotenv)
[Dotenv](https://github.com/motdotla/dotenv)
[ClanLabs](https://docs.clanlabs.co/api-reference)
38 changes: 32 additions & 6 deletions routes/tniv/group/internal/join-requests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const express = require('express');
const path = require('path');
const router = express.Router();
const JoinRequest = require(path.join(global.__basedir, 'utils/group.js')).JoinRequest;

const Group = require(path.join(global.__basedir, 'utils/group.js')).Group;
/**
* @swagger
* /tniv/group/internal/join-requests/accept:
* /tniv/group/internal/join-requests:
* post:
* summary: Accept a join request for a user in a specific group.
* security:
Expand All @@ -25,7 +25,7 @@ const JoinRequest = require(path.join(global.__basedir, 'utils/group.js')).JoinR
* 500:
* description: Server error
*/
router.post('/accept', async (req, res) => {
router.post('/', async (req, res) => {
try {
const { userId } = req.query || {};

Expand All @@ -43,8 +43,8 @@ router.post('/accept', async (req, res) => {

/**
* @swagger
* /tniv/group/internal/join-requests/decline:
* post:
* /tniv/group/internal/join-requests:
* delete:
* summary: Decline a join request for a user in a specific group.
* security:
* - apiKey: []
Expand All @@ -62,7 +62,7 @@ router.post('/accept', async (req, res) => {
* 500:
* description: Server error
*/
router.post('/decline', async (req, res) => {
router.delete('/', async (req, res) => {
try {
const { userId } = req.query || {};

Expand Down Expand Up @@ -104,4 +104,30 @@ router.get('/', async (req, res) => {
}
});

/**
* @swagger
* /tniv/group/internal/join-requests:
* patch:
* summary: Process current join requests. Verifications are Account Age > 100 days, not in EIC registry, not in External Registries
* security:
* - apiKey: []
* tags:
* - TNIV/Group/Internal
* responses:
* 200:
* description: Successfully processed
* 500:
* description: Server error
*/
router.patch('/', async (req, res) => {
try {
const joinRequest = new JoinRequest();
await joinRequest.processPending();

res.status(200).json({ message: 'Join requests processed successfully.' });
} catch (err) {
res.status(500).json({ error: 'Error processing join requests: ' + err.message });
}
});

module.exports = router;
27 changes: 23 additions & 4 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,29 @@ describe("EIC Cleanup", () => {
})
})
test("Cleanup test case", async () => {
await runTest("Cleanup test case", async () => {
const Case = require(path.join(global.__basedir, 'db/schemas/eic/case.js'));
const result = await Case.deleteOne({ caseId: 0 });
expect(result.deletedCount).toBeLessThanOrEqual(1);
await runTest("Cleanup test case", async () => {
const Case = require(path.join(global.__basedir, 'db/schemas/eic/case.js'));
const result = await Case.deleteOne({ caseId: 0 });
expect(result.deletedCount).toBeLessThanOrEqual(1);
});
});
});

describe("External Case Registries", () => {
test("Get cases from registry", async () => {
await runTest("Get cases from registry", async () => {
const RegistryCase = require(path.join(global.__basedir, 'utils/registry.js'));
const caseInstance = new RegistryCase();
const cases = await caseInstance.getCases();
expect(Array.isArray(cases)).toBe(true);
});
});
test("Get a specific case from registry", async () => {
await runTest("Get cases from registry", async () => {
const RegistryCase = require(path.join(global.__basedir, 'utils/registry.js'));
const caseInstance = new RegistryCase("CW", "1478099365", false); // goggybo
const cases = await caseInstance.getCases();
expect(cases.usernames).toBe("goggybo");
});
});
});
Loading
Loading