-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5964 from beyondessential/release-2024-43
Release 2024-43
- Loading branch information
Showing
91 changed files
with
1,365 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
packages/database/src/__tests__/modelClasses/SurveyResponse.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Tupaia | ||
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd | ||
*/ | ||
import { getLeaderboard } from '../../modelClasses/SurveyResponse'; | ||
|
||
const USERS_EXCLUDED_FROM_LEADER_BOARD = [ | ||
"'edmofro@gmail.com'", | ||
"'kahlinda.mahoney@gmail.com'", | ||
"'lparish1980@gmail.com'", | ||
"'sus.lake@gmail.com'", | ||
"'michaelnunan@hotmail.com'", | ||
"'vanbeekandrew@gmail.com'", | ||
"'gerardckelly@gmail.com'", | ||
"'geoffreyfisher@hotmail.com'", | ||
"'unicef.laos.edu@gmail.com'", | ||
]; | ||
const SYSTEM_USERS = ["'tamanu-server@tupaia.org'", "'public@tupaia.org'", "'josh@sussol.net'"]; | ||
|
||
const whitespace = /\s/g; | ||
const expectToBe = (expected, received) => { | ||
expect(received.replace(whitespace, '')).toBe(expected.replace(whitespace, '')); | ||
}; | ||
|
||
describe('getLeaderboard()', () => { | ||
it('should filter out internal users on standard projects', async () => { | ||
const expectedLeaderboard = `SELECT r.user_id, user_account.first_name, user_account.last_name, r.coconuts, r.pigs | ||
FROM ( | ||
SELECT user_id, FLOOR(COUNT(*)) as coconuts, FLOOR(COUNT(*) / 100) as pigs | ||
FROM survey_response | ||
JOIN survey on survey.id=survey_id | ||
WHERE survey.project_id = ? | ||
GROUP BY user_id | ||
) r | ||
JOIN user_account on user_account.id = r.user_id | ||
WHERE email NOT IN (${[...SYSTEM_USERS, ...USERS_EXCLUDED_FROM_LEADER_BOARD].join(', ')}) | ||
AND email NOT LIKE '%@beyondessential.com.au' AND email NOT LIKE '%@bes.au' | ||
ORDER BY coconuts DESC | ||
LIMIT ?;`; | ||
|
||
expectToBe(getLeaderboard('5dfc6eaf61f76a497716cddf'), expectedLeaderboard); | ||
}); | ||
|
||
it('should not filter out internal users on internal projects', async () => { | ||
const INTERNAL_PROJECT_IDS = [ | ||
'6684ac9d0f018e110b000a00', // bes_asset_demo | ||
'66a03660718c54751609eeed', // bes_asset_tracker | ||
'6704622a45a4fc4941071605', // bes_reporting | ||
]; | ||
const expectedLeaderboard = `SELECT r.user_id, user_account.first_name, user_account.last_name, r.coconuts, r.pigs | ||
FROM ( | ||
SELECT user_id, FLOOR(COUNT(*)) as coconuts, FLOOR(COUNT(*) / 100) as pigs | ||
FROM survey_response | ||
JOIN survey on survey.id=survey_id | ||
WHERE survey.project_id = ? | ||
GROUP BY user_id | ||
) r | ||
JOIN user_account on user_account.id = r.user_id | ||
WHERE email NOT IN (${SYSTEM_USERS.join(', ')}) | ||
ORDER BY coconuts DESC | ||
LIMIT ?;`; | ||
|
||
INTERNAL_PROJECT_IDS.forEach(projectId => { | ||
expectToBe(getLeaderboard(projectId), expectedLeaderboard); | ||
}); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
...abase/src/migrations/20241003224849-addDateColumnToMeditrakDeviceTable-modifies-schema.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
var dbm; | ||
var type; | ||
var seed; | ||
|
||
/** | ||
* We receive the dbmigrate dependency from dbmigrate initially. | ||
* This enables us to not have to rely on NODE_PATH. | ||
*/ | ||
exports.setup = function (options, seedLink) { | ||
dbm = options.dbmigrate; | ||
type = dbm.dataType; | ||
seed = seedLink; | ||
}; | ||
|
||
exports.up = function (db) { | ||
return db.runSql(` | ||
ALTER TABLE meditrak_device | ||
ADD COLUMN last_login TIMESTAMP; | ||
`); | ||
}; | ||
|
||
exports.down = function (db) { | ||
return db.runSql(` | ||
ALTER TABLE meditrak_device DROP COLUMN last_login; | ||
`); | ||
}; | ||
|
||
exports._meta = { | ||
version: 1, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.