Skip to content

Commit

Permalink
Merge pull request #200 from UniversityOfHelsinkiCS/studytrack-opt-out
Browse files Browse the repository at this point in the history
Studytrack opt out feature
  • Loading branch information
HRemonen authored Dec 16, 2024
2 parents b6ff2e3 + eed668e commit 9b45e5d
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/client/components/ThesisPage/ThesisEditForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ const ThesisEditForm: FC<{
<Select
data-testid="study-track-select-input"
required
value={editedThesis.studyTrackId}
value={editedThesis.studyTrackId ?? ''}
id="studyTrackId"
label="Study Track"
name="studyTrackId"
Expand All @@ -282,6 +282,9 @@ const ThesisEditForm: FC<{
(error) => error.path[0] === 'studyTrackId'
)}
>
<MenuItem value="">
<em>{t('common:none')}</em>
</MenuItem>
{sortedStudyTracks.map((studyTrack) => (
<MenuItem key={studyTrack.id} value={studyTrack.id}>
{studyTrack.name[language]}
Expand Down
10 changes: 10 additions & 0 deletions src/client/hooks/useThesesMutation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export const useCreateThesisMutation = () => {
const mutationFn = async (data: ThesisData) => {
const formData = new FormData()

// Check for the empty studyTrackId
// If it's an empty string, set it to null
if (data.studyTrackId === '') {
data.studyTrackId = null
}
formData.append('json', JSON.stringify(data))

if (data.researchPlan instanceof Blob) {
Expand Down Expand Up @@ -40,6 +45,11 @@ export const useEditThesisMutation = () => {
}) => {
const formData = new FormData()

// Check for the empty studyTrackId
// If it's an empty string, set it to null
if (data.studyTrackId === '') {
data.studyTrackId = null
}
formData.append('json', JSON.stringify(data))

if (data.researchPlan instanceof Blob) {
Expand Down
3 changes: 2 additions & 1 deletion src/client/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"removeButton": "Remove",
"error": "Error",
"thesisPreview": "Thesis preview",
"theses": "Theses"
"theses": "Theses",
"none": "No studytrack"
},
"eventLog": {
"thesis": "Thesis",
Expand Down
3 changes: 2 additions & 1 deletion src/client/locales/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"removeConfirmation": "Vahvista poisto kirjoittamalla (<strong>{{confirmationText}}</strong>) alla olevaan kenttään:",
"error": "Virhe",
"thesisPreview": "Tutkielman esikatselu",
"theses": "Tutkielmat"
"theses": "Tutkielmat",
"none": "Ei opintosuuntaa"
},
"eventLog": {
"thesis": "Tutkielma",
Expand Down
52 changes: 52 additions & 0 deletions src/server/routes/thesis.integration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1935,6 +1935,58 @@ describe('thesis router', () => {
expect(eventLog).not.toBeNull()
})

it('should return 201 with empty studytrack and log the event', async () => {
const newThesis = {
programId: 'New program',
studyTrackId: null,
topic: 'New topic',
status: 'PLANNING',
startDate: '1970-01-01T00:00:00.000Z',
targetDate: '2070-01-01T00:00:00.000Z',
supervisions: [
{
user: user1,
percentage: 100,
isExternal: false,
isPrimarySupervisor: true,
},
],
graders: [
{
user: user4,
isPrimaryGrader: true,
isExternal: false,
},
],
authors: [user2],
}

const response = await request
.post('/api/theses')
.set('hygroupcn', 'grp-toska')
.attach(
'waysOfWorking',
path.resolve(dirname(fileURLToPath(import.meta.url)), './index.ts')
)
.attach(
'researchPlan',
path.resolve(dirname(fileURLToPath(import.meta.url)), './index.ts')
)
.field('json', JSON.stringify(newThesis))

expect(response.status).toEqual(201)

const eventLog = await EventLog.findOne({
where: { type: 'THESIS_CREATED', thesisId: response.body.id },
})

expect(eventLog).not.toBeNull()

const thesis = await Thesis.findByPk(response.body.id)
expect(thesis).not.toBeNull()
expect(thesis.studyTrackId).toBeNull()
})

it('should return 400 and not log the event if the request is missing a required field', async () => {
const newThesis = {
programId: 'New program',
Expand Down

0 comments on commit 9b45e5d

Please sign in to comment.