2022-02-27 13:02:28 -05:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
import request from 'supertest';
|
|
|
|
|
2022-10-23 14:31:17 -04:00
|
|
|
import { GuestAccess } from '../../src/config/guest_access.enum';
|
|
|
|
import { createDefaultMockNoteConfig } from '../../src/config/mock/note.config.mock';
|
|
|
|
import { NoteConfig } from '../../src/config/note.config';
|
2022-02-27 13:02:28 -05:00
|
|
|
import { LoginDto } from '../../src/identity/local/login.dto';
|
2022-09-24 20:05:30 -04:00
|
|
|
import {
|
|
|
|
password1,
|
|
|
|
TestSetup,
|
|
|
|
TestSetupBuilder,
|
|
|
|
username1,
|
|
|
|
} from '../test-setup';
|
2022-02-27 13:02:28 -05:00
|
|
|
|
|
|
|
describe('Groups', () => {
|
|
|
|
let testSetup: TestSetup;
|
|
|
|
let testuser1Session: request.SuperAgentTest;
|
2022-10-23 14:31:17 -04:00
|
|
|
const noteConfigMock: NoteConfig = createDefaultMockNoteConfig();
|
2022-02-27 13:02:28 -05:00
|
|
|
|
|
|
|
beforeEach(async () => {
|
2022-10-23 14:31:17 -04:00
|
|
|
testSetup = await TestSetupBuilder.create({
|
|
|
|
noteConfigMock: noteConfigMock,
|
|
|
|
})
|
|
|
|
.withUsers()
|
|
|
|
.build();
|
2022-02-27 13:02:28 -05:00
|
|
|
await testSetup.app.init();
|
|
|
|
|
|
|
|
// create a test group
|
|
|
|
await testSetup.groupService.createGroup('testgroup1', 'testgroup1', false);
|
|
|
|
|
|
|
|
// log in to create a session
|
|
|
|
const loginDto: LoginDto = {
|
2022-09-24 20:05:30 -04:00
|
|
|
password: password1,
|
|
|
|
username: username1,
|
2022-02-27 13:02:28 -05:00
|
|
|
};
|
|
|
|
testuser1Session = request.agent(testSetup.app.getHttpServer());
|
|
|
|
await testuser1Session
|
|
|
|
.post('/api/private/auth/local/login')
|
|
|
|
.set('Content-Type', 'application/json')
|
|
|
|
.send(JSON.stringify(loginDto))
|
|
|
|
.expect(201);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
await testSetup.app.close();
|
2022-03-04 07:13:46 -05:00
|
|
|
await testSetup.cleanup();
|
2022-02-27 13:02:28 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('details for existing groups can be retrieved', async () => {
|
|
|
|
const response = await testuser1Session.get(
|
|
|
|
'/api/private/groups/testgroup1',
|
|
|
|
);
|
|
|
|
expect(response.status).toBe(200);
|
|
|
|
expect(response.body.name).toBe('testgroup1');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('details for non-existing groups cannot be retrieved', async () => {
|
|
|
|
const response = await testuser1Session.get(
|
|
|
|
'/api/private/groups/i_dont_exist',
|
|
|
|
);
|
|
|
|
expect(response.status).toBe(404);
|
|
|
|
});
|
|
|
|
|
2022-10-23 14:31:17 -04:00
|
|
|
describe('API requires authentication', () => {
|
|
|
|
beforeAll(() => {
|
|
|
|
noteConfigMock.guestAccess = GuestAccess.DENY;
|
|
|
|
});
|
|
|
|
test('get group', async () => {
|
|
|
|
const response = await request(testSetup.app.getHttpServer()).get(
|
|
|
|
'/api/private/groups/testgroup1',
|
|
|
|
);
|
|
|
|
expect(response.status).toBe(401);
|
|
|
|
});
|
2022-02-27 13:02:28 -05:00
|
|
|
});
|
|
|
|
});
|