Skip to content
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

feat: achievement integration tests #956

Merged
Merged
Show file tree
Hide file tree
Changes from 9 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
7 changes: 5 additions & 2 deletions common/achievement/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export enum TemplateSelectEnum {
const achievementTemplates: Map<TemplateSelectEnum, Map<string, Achievement_template[]>> = new Map();

async function getAchievementTemplates(select: TemplateSelectEnum): Promise<Map<string, Achievement_template[]>> {
if (!achievementTemplates.has(select)) {
if (!achievementTemplates.has(select) || !achievementTemplates[select]) {
dhenkel92 marked this conversation as resolved.
Show resolved Hide resolved
achievementTemplates.set(select, new Map());

const templatesFromDB = await prisma.achievement_template.findMany({
Expand Down Expand Up @@ -57,7 +57,10 @@ async function getTemplatesByMetrics(metricsForAction: Metric[]) {
return [];
}
for (const metric of metricsForAction) {
templatesForAction = [...templatesForAction, ...templatesByMetric.get(metric.metricName)];
const templatesForMetric = templatesByMetric.get(metric.metricName);
if (templatesForMetric) {
templatesForAction = [...templatesForAction, ...templatesForMetric];
}
}
return templatesForAction;
}
Expand Down
13 changes: 7 additions & 6 deletions common/achievement/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export async function getBucketContext(userID: string, relation?: string): Promi

let matches = [];
if (!relationType || relationType === 'match') {
whereClause[`${userType}Id`] = id;
matches = await prisma.match.findMany({
where: { ...whereClause, [`${userType}Id`]: id },
dhenkel92 marked this conversation as resolved.
Show resolved Hide resolved
select: {
Expand All @@ -62,12 +63,12 @@ export async function getBucketContext(userID: string, relation?: string): Promi

let subcourses = [];
if (!relationType || relationType === 'subcourse') {
let subcourseWhere = whereClause;
if (userType === 'student') {
subcourseWhere = { ...subcourseWhere, subcourse_instructors_student: { some: { studentId: id } } };
} else {
subcourseWhere = { ...subcourseWhere, subcourse_participants_pupil: { some: { pupilId: id } } };
}
delete whereClause[`${userType}Id`];
const userClause =
userType === 'student'
? { subcourse_instructors_student: { some: { studentId: id } } }
: { subcourse_participants_pupil: { some: { pupilId: id } } };
const subcourseWhere = { ...whereClause, ...userClause };
dhenkel92 marked this conversation as resolved.
Show resolved Hide resolved
subcourses = await prisma.subcourse.findMany({
where: subcourseWhere,
select: {
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/02_screening.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { test } from './base';
import { adminClient, createUserClient } from './base/clients';
import { instructorOne, instructorTwo, pupilOne, studentOne } from './01_user';

const screenerOne = test('Admin can create Screener Account', async () => {
export const screenerOne = test('Admin can create Screener Account', async () => {
const email = `test+${randomBytes(10).toString('base64')}@lern-fair.de`;
const firstname = randomBytes(10).toString('base64');
const lastname = randomBytes(10).toString('base64');
Expand Down
Loading