Skip to content

Commit

Permalink
Merge branch 'main' into THR-18-dev-feature-h5p-editor
Browse files Browse the repository at this point in the history
  • Loading branch information
SteKrause authored Sep 19, 2023
2 parents 75ff0b6 + b0e9f42 commit f0cf579
Show file tree
Hide file tree
Showing 141 changed files with 4,165 additions and 1,942 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ jobs:
- name: test image exists
run: |
mkdir -p ~/.docker
echo '{"experimental": "enabled"}' >> ~/.docker/config.json
echo "IMAGE_EXISTS=$(docker manifest inspect ghcr.io/${{ github.repository }}:${{ needs.branch_meta.outputs.sha }} > /dev/null && echo 1 || echo 0)" >> $GITHUB_ENV
- name: Set up Docker Buildx
Expand Down Expand Up @@ -83,8 +81,6 @@ jobs:
- name: test image exists (file storage)
run: |
mkdir -p ~/.docker
echo '{"experimental": "enabled"}' >> ~/.docker/config.json
echo "IMAGE_EXISTS=$(docker manifest inspect ghcr.io/${{ github.repository }}:file-storage-${{ needs.branch_meta.outputs.sha }} > /dev/null && echo 1 || echo 0)" >> $GITHUB_ENV
- name: Set up Docker Buildx (file storage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,49 @@ data:

# ========== End of the Dev IServ configuration section.

# ========== Start of the Test BRB Univention LDAP system (also used on the REF BRB) configuration section.

# This is currently performed for any 'brb-*' namespace ('brb-main' for example).

if [[ "$NS" =~ ^brb-[^\s]+$ ]]; then
UNIVENTION_LDAP_SYSTEM_ID=621beef78ec63ea12a3adae6
UNIVENTION_LDAP_FEDERAL_STATE_ID=0000b186816abba584714c53

# Encrypt LDAP server's search user password.
UNIVENTION_LDAP_SEARCH_USER_PASSWORD=$(node scripts/secret.js -s $AES_KEY -e $UNIVENTION_LDAP_SEARCH_USER_PASSWORD)

# Add (or replace) document with the test BRB Univention LDAP system configuration.
mongosh $DATABASE__URL --eval 'db.systems.replaceOne(
{
"_id": ObjectId("'$UNIVENTION_LDAP_SYSTEM_ID'"),
},
{
"_id": ObjectId("'$UNIVENTION_LDAP_SYSTEM_ID'"),
"alias": "TEST BRB UNIVENTION LDAP",
"ldapConfig": {
"active": true,
"federalState": ObjectId("'$UNIVENTION_LDAP_FEDERAL_STATE_ID'"),
"url": "'$UNIVENTION_LDAP_URL'",
"rootPath": "'$UNIVENTION_LDAP_ROOT_PATH'",
"searchUser": "'$UNIVENTION_LDAP_SEARCH_USER'",
"searchUserPassword": "'$UNIVENTION_LDAP_SEARCH_USER_PASSWORD'",
"provider": "univention",
"providerOptions": {
"userAttributeNameMapping": {},
"roleAttributeNameMapping": {},
"classAttributeNameMapping": {}
}
},
"type": "ldap"
},
{
"upsert": true
}
);'
fi

# ========== End of the Test BRB Univention LDAP system (also used on the REF BRB) configuration section.

# ========== Start of the Bettermarks tool configuration section.

# This is currently performed only for the following 4 namespaces:
Expand Down
3 changes: 3 additions & 0 deletions apps/server/src/apps/server.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { enableOpenApiDocs } from '@shared/controller/swagger';
import { Mail, MailService } from '@shared/infra/mail';
import { LegacyLogger, Logger } from '@src/core/logger';
import { AccountService } from '@src/modules/account/services/account.service';
import { TeamService } from '@src/modules/teams/service/team.service';
import { AccountValidationService } from '@src/modules/account/services/account.validation.service';
import { AccountUc } from '@src/modules/account/uc/account.uc';
import { CollaborativeStorageUc } from '@src/modules/collaborative-storage/uc/collaborative-storage.uc';
Expand Down Expand Up @@ -76,6 +77,8 @@ async function bootstrap() {
feathersExpress.services['nest-account-uc'] = nestApp.get(AccountUc);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
feathersExpress.services['nest-collaborative-storage-uc'] = nestApp.get(CollaborativeStorageUc);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
feathersExpress.services['nest-team-service'] = nestApp.get(TeamService);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
feathersExpress.services['nest-orm'] = orm;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,79 @@
import { INestApplicationContext } from '@nestjs/common';
import { BootstrapConsole, ConsoleService } from 'nestjs-console';
import { ConsoleWriterService } from '@shared/infra/console';
import { ServerConsoleModule } from '@src/console/console.module';
import { CommanderError } from 'commander';
import { execute, TestBootstrapConsole } from './test-bootstrap.console';
import { BootstrapConsole, ConsoleService } from 'nestjs-console';
import { TestBootstrapConsole, execute } from './test-bootstrap.console';

describe('DatabaseManagementConsole (API)', () => {
let app: INestApplicationContext;
let console: BootstrapConsole;
let bootstrap: BootstrapConsole;
let consoleService: ConsoleService;
beforeAll(async () => {
console = new TestBootstrapConsole({
let consoleWriter: ConsoleWriterService;

beforeEach(async () => {
bootstrap = new TestBootstrapConsole({
module: ServerConsoleModule,
useDecorators: true,
});
app = await console.init();
app = await bootstrap.init();
await app.init();
consoleService = app.get(ConsoleService);
consoleWriter = app.get(ConsoleWriterService);
});

afterAll(async () => {
afterEach(async () => {
consoleService.resetCli();
await app.close();
});

describe('Command "database"', () => {
beforeEach(() => {
const setup = () => {
const cli = consoleService.getCli('database');
const exitFn = (err: CommanderError) => {
if (err.exitCode !== 0) throw err;
};
cli?.exitOverride(exitFn);
const rootCli = consoleService.getRootCli();
rootCli.exitOverride(exitFn);
});
const spyConsoleWriterInfo = jest.spyOn(consoleWriter, 'info');
return { spyConsoleWriterInfo };
};
describe('when command not exists', () => {
it('should fail for unknown command', async () => {
setup();
await expect(execute(bootstrap, ['database', 'not_existing_command'])).rejects.toThrow(
`error: unknown command 'not_existing_command'`
);

afterEach(() => {
consoleService.resetCli();
consoleService.resetCli();
});
});

it('should fail for unknown command', async () => {
await expect(execute(console, ['database', 'not_existing_command'])).rejects.toThrow(
`error: unknown command 'not_existing_command'`
);
});
it('should provide command "seed"', async () => {
await execute(console, ['database', 'seed']);
});
it('should provide command "export"', async () => {
await execute(console, ['database', 'export']);
describe('when command exists', () => {
it('should provide command "seed"', async () => {
const { spyConsoleWriterInfo } = setup();

await execute(bootstrap, ['database', 'seed']);

expect(spyConsoleWriterInfo).toBeCalled();
});

it('should provide command "export"', async () => {
const { spyConsoleWriterInfo } = setup();

await execute(bootstrap, ['database', 'export']);

expect(spyConsoleWriterInfo).toBeCalled();
});

it('should provide command "sync-indexes"', async () => {
const { spyConsoleWriterInfo } = setup();

await execute(bootstrap, ['database', 'sync-indexes']);

expect(spyConsoleWriterInfo).toBeCalled();
});
});
});
});
10 changes: 9 additions & 1 deletion apps/server/src/console/api-test/test-bootstrap.console.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { createMock } from '@golevelup/ts-jest';
import { Test, TestingModule } from '@nestjs/testing';
import { ConsoleWriterService } from '@shared/infra/console';
import { DatabaseManagementUc } from '@src/modules/management/uc/database-management.uc';
import { AbstractBootstrapConsole, BootstrapConsole } from 'nestjs-console';

export class TestBootstrapConsole extends AbstractBootstrapConsole<TestingModule> {
create(): Promise<TestingModule> {
return Test.createTestingModule({
imports: [this.options.module],
}).compile();
})
.overrideProvider(DatabaseManagementUc)
.useValue(createMock<DatabaseManagementUc>())
.overrideProvider(ConsoleWriterService)
.useValue(createMock<ConsoleWriterService>())
.compile();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { ObjectId } from '@mikro-orm/mongodb';
import { CACHE_MANAGER } from '@nestjs/common';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { Test, TestingModule } from '@nestjs/testing';
import { CacheService } from '@shared/infra/cache';
import { CacheStoreType } from '@shared/infra/cache/interface/cache-store-type.enum';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CACHE_MANAGER, Inject, Injectable } from '@nestjs/common';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { Inject, Injectable } from '@nestjs/common';
import { CacheService } from '@shared/infra/cache';
import { CacheStoreType } from '@shared/infra/cache/interface/cache-store-type.enum';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ describe('submission create (api)', () => {
expect(result.id).toBeDefined();
expect(result.timestamps.createdAt).toBeDefined();
expect(result.timestamps.lastUpdatedAt).toBeDefined();
expect(result.userId).toBe(studentUser.id);
expect(result.userData.userId).toBe(studentUser.id);
expect(result.userData.firstName).toBe('John');
expect(result.userData.lastName).toBe('Mr Doe');
});

it('should actually create the submission item', async () => {
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/modules/board/controller/dto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './card.url.params';
export * from './element';
export * from './submission-item';
export * from './timestamps.response';
export * from './user-data.response';
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { ApiProperty } from '@nestjs/swagger';
import { TimestampsResponse } from '../timestamps.response';
import { UserDataResponse } from '../user-data.response';

export class SubmissionItemResponse {
constructor({ id, timestamps, completed, userId }: SubmissionItemResponse) {
constructor({ id, timestamps, completed, userData }: SubmissionItemResponse) {
this.id = id;
this.timestamps = timestamps;
this.completed = completed;
this.userId = userId;
this.userData = userData;
}

@ApiProperty({ pattern: '[a-f0-9]{24}' })
Expand All @@ -19,5 +20,5 @@ export class SubmissionItemResponse {
completed: boolean;

@ApiProperty()
userId: string;
userData: UserDataResponse;
}
18 changes: 18 additions & 0 deletions apps/server/src/modules/board/controller/dto/user-data.response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ApiProperty } from '@nestjs/swagger';

export class UserDataResponse {
constructor({ userId, firstName, lastName }: UserDataResponse) {
this.userId = userId;
this.firstName = firstName;
this.lastName = lastName;
}

@ApiProperty()
firstName!: string;

@ApiProperty()
lastName!: string;

@ApiProperty()
userId!: string;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SubmissionItem } from '@shared/domain';
import { SubmissionItemResponse, TimestampsResponse } from '../dto';
import { SubmissionItemResponse, TimestampsResponse, UserDataResponse } from '../dto';

export class SubmissionItemResponseMapper {
private static instance: SubmissionItemResponseMapper;
Expand All @@ -14,13 +14,18 @@ export class SubmissionItemResponseMapper {

public mapToResponse(submissionItem: SubmissionItem): SubmissionItemResponse {
const result = new SubmissionItemResponse({
completed: submissionItem.completed,
id: submissionItem.id,
timestamps: new TimestampsResponse({
lastUpdatedAt: submissionItem.updatedAt,
createdAt: submissionItem.createdAt,
}),
completed: submissionItem.completed,
userId: submissionItem.userId,
userData: new UserDataResponse({
// TODO: put valid user info here which comes from the submission owner
firstName: 'John',
lastName: 'Mr Doe',
userId: submissionItem.userId,
}),
});

return result;
Expand Down
9 changes: 9 additions & 0 deletions apps/server/src/modules/class/class.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { ClassService } from './service';
import { ClassesRepo } from './repo';

@Module({
providers: [ClassService, ClassesRepo],
exports: [ClassService],
})
export class ClassModule {}
15 changes: 15 additions & 0 deletions apps/server/src/modules/class/domain/class-source-options.do.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export interface ClassSourceOptionsProps {
tspUid?: string;
}

export class ClassSourceOptions {
protected props: ClassSourceOptionsProps;

constructor(props: ClassSourceOptionsProps) {
this.props = props;
}

get tspUid(): string | undefined {
return this.props.tspUid;
}
}
Loading

0 comments on commit f0cf579

Please sign in to comment.