Skip to content

Commit 7ad8ba9

Browse files
committed
paradata: export interview's _isCompleted response field
fixes #1343 The actual completion status of an interview is currently stored in the `_isCompleted` field of the `response` data, so it is exported with the paradata under the `interview_is_completed` column.
1 parent 93b987a commit 7ad8ba9

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

packages/evolution-backend/src/models/__tests__/paradataEvents.db.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const testInterviewAttributes2 = {
5757
is_active: true,
5858
is_completed: undefined,
5959
response: {
60+
_isCompleted: true,
6061
accessCode: '11111',
6162
booleanField: true,
6263
},
@@ -264,6 +265,7 @@ describe('Stream paradata', () => {
264265
expect(row.values_by_path).toEqual(log?.valuesByPath ? log.valuesByPath : null);
265266
expect(row.unset_paths).toEqual(log?.unsetPaths ? log.unsetPaths : null);
266267
expect(row.user_id).toBeNull();
268+
expect(row.interview_is_completed).toBeNull();
267269

268270
nbLogs++;
269271
})
@@ -346,6 +348,8 @@ describe('Stream paradata', () => {
346348
expect(interviewLogsForFirstCompleted).toEqual(false);
347349
interviewLogsForFirstCompleted = true;
348350
currentInterviewIndex = 0;
351+
// Should be the second interview now, with completed status true
352+
expect(row.interview_is_completed).toEqual('true');
349353
}
350354

351355
// Expected sort by timestamp, timestamp should be greater than previous
@@ -469,6 +473,7 @@ describe('Query paradata temp view', () => {
469473

470474
const incompleteInterviewAttributes = _cloneDeep(testInterviewAttributes2);
471475
delete incompleteInterviewAttributes.id;
476+
delete incompleteInterviewAttributes.response._isCompleted;
472477

473478
let trx: Knex.Transaction;
474479

packages/evolution-backend/src/models/paradataEvents.db.queries.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ const getParadataStream = function (interviewId?: number) {
7676
'is_questionable',
7777
'user_id',
7878
'event_type',
79+
knex.raw('response->>\'_isCompleted\' as interview_is_completed'),
7980
knex.raw('to_char(timestamp AT TIME ZONE \'UTC\', \'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"\') as event_date'),
8081
knex.raw('extract(epoch from timestamp) as timestamp_sec'),
8182
knex.raw('event_data->\'valuesByPath\' as values_by_path'),

packages/evolution-backend/src/services/adminExport/__tests__/exportInterviewLogs.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ beforeEach(() => {
4343
describe('exportInterviewLogTask', () => {
4444

4545
// Common data for all logs of the interview
46-
const commonInterviewData = { id: 1, uuid: 'uuid', 'updated_at': '2024-10-11 09:02:00', is_valid: true, is_completed: true, is_validated: null, is_questionable: null, user_id: null };
47-
const commonInterviewDataInRows = { id: '1', uuid: 'uuid', 'updated_at': '2024-10-11 09:02:00', is_valid: 'true', is_completed: 'true', is_validated: '', is_questionable: '', user_id: '' };
46+
const commonInterviewData = { id: 1, uuid: 'uuid', 'updated_at': '2024-10-11 09:02:00', is_valid: true, is_completed: true, is_validated: null, is_questionable: null, interview_is_completed: true, user_id: null };
47+
const commonInterviewDataInRows = { id: '1', uuid: 'uuid', 'updated_at': '2024-10-11 09:02:00', is_valid: 'true', is_completed: 'true', is_validated: '', is_questionable: '', interview_is_completed: 'true', user_id: '' };
4848

4949
const logs: { [key: string]: any }[] = [
5050
{

0 commit comments

Comments
 (0)