-
Notifications
You must be signed in to change notification settings - Fork 34
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
Issue/2009 Notifications Added #2064
Merged
FrenjaminBanklin
merged 47 commits into
ucfopen:dev/34-bismuth
from
RachelDau:issue/2009-notification-added
May 9, 2024
Merged
Changes from 36 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
8ec51cc
migration files
RachelDau de8b055
display notification in nav
RachelDau 9809933
notification css file
RachelDau 83ee351
nav-util functions and viewer app update
RachelDau d74d2a1
nav code cleanup
RachelDau 015f169
nav unit tests and snapshots
RachelDau 16cb203
nav store and migration file update
RachelDau 1fe112e
initial commit for new notifiction state viewer
RachelDau a40b891
initial commit for visits file
RachelDau 12c9af3
viewer users state added
RachelDau 5f60125
viewer notifications state updated
RachelDau 1eee465
last login checked for logic
RachelDau a33a0b0
Merge branch 'dev/31-taconite' into issue/2009-notification-added
RachelDau 7591c1a
adds notifications to dashboard
RachelDau 73a7500
merge dev-32-pigeonite
RachelDau 08f91c8
fix notification implementation and tests
RachelDau ac6f836
Merge branch 'dev/33-serpierite' into issue/2009-notification-added
RachelDau b954c5d
remove file
RachelDau 86ff23e
fix dependencies
RachelDau e6e3e51
code clean-up
RachelDau b6d4df3
Nav Clean-up code
RachelDau 1cd175a
Visits Code Clean-up
RachelDau acf12dd
Visits code clean-up
RachelDau a6b3660
Update visits.js
RachelDau b298b88
fix last notification fails to exit issue
RachelDau 251bdc9
dashboard clean-up
RachelDau 4b98337
CSS Style update for notifications
RachelDau 0e3102c
notification indicator and drop down menu added
RachelDau af88209
Dashboard client and server code clean-up
RachelDau d6ca441
default.jsx code cleanup
RachelDau fce6ab2
imports updated for notification component
RachelDau 2c76339
removed hidden Notifications updated logic
RachelDau ec3b5af
updated migration files
RachelDau 846e6e4
notification style update and jest tests written
RachelDau d87cb8b
css style exit button outside scroll
RachelDau e4369ab
background removed exit button
RachelDau b96d0c1
tab order accessibility update
RachelDau 674b75b
update no notifications screen
RachelDau d4830eb
updates scaling notifications to account for long strings
RachelDau 5556eb5
fix for safari issue with notification indicator
RachelDau 7c74f45
capitialized Index
RachelDau 2add759
Modal added for notifications
RachelDau d758ecf
remove comments
RachelDau 5dc37a8
migrations regenerated and unit tests updated
RachelDau 6ca28de
unit tests updated for notifications
RachelDau c37cc24
notification unit tests for button click updated
RachelDau ad39599
express-current-user test updated date mock
RachelDau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
65 changes: 65 additions & 0 deletions
65
packages/app/obojobo-express/__tests__/viewer_notification_state.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,65 @@ | ||
const db = require('../server/db') | ||
const { | ||
getNotifications, | ||
getRecentNotifications, | ||
setLastLogin | ||
} = require('../server/viewer/viewer_notification_state') | ||
|
||
jest.mock('../server/db') | ||
describe('db', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks() | ||
jest.resetModules() | ||
}) | ||
|
||
test('returns notifications when passed ids', () => { | ||
const fakeNotifications = [ | ||
{ title: 'Notification 1', text: 'This is notification 1' }, | ||
{ title: 'Notification 2', text: 'This is notification 2' } | ||
] | ||
db.manyOrNone.mockResolvedValue(fakeNotifications) | ||
|
||
return getNotifications([1, 2]).then(result => { | ||
expect(result).toEqual(fakeNotifications) | ||
expect(db.manyOrNone).toHaveBeenCalledWith(expect.any(String), { ids: [1, 2] }) | ||
}) | ||
}) | ||
|
||
test('returns undefined when passed ids as 0', () => { | ||
return expect(getNotifications(0)).toBeUndefined() | ||
}) | ||
|
||
test('returns notifications created after a given date', () => { | ||
const fakeNotifications = [{ id: 1 }, { id: 2 }] | ||
db.manyOrNone.mockResolvedValue(fakeNotifications) | ||
|
||
return getRecentNotifications('2022-01-01').then(result => { | ||
expect(result).toEqual(fakeNotifications) | ||
expect(db.manyOrNone).toHaveBeenCalledWith(expect.any(String), { date: '2022-01-01' }) | ||
}) | ||
}) | ||
|
||
test('should insert a new record if the user does not exist', () => { | ||
db.none.mockResolvedValue() | ||
|
||
const userId = 1 | ||
const today = '2023-09-13' | ||
|
||
return setLastLogin(userId, today).then(() => { | ||
expect(db.none).toHaveBeenCalledWith(expect.stringContaining('INSERT INTO users'), { | ||
userId, | ||
today | ||
}) | ||
}) | ||
}) | ||
|
||
test('should handle other errors from db.none', () => { | ||
const errorMessage = 'Database error' | ||
db.none.mockRejectedValue(new Error(errorMessage)) | ||
|
||
const userId = 1 | ||
const today = '2023-09-13' | ||
|
||
return expect(setLastLogin(userId, today)).rejects.toThrow(errorMessage) | ||
}) | ||
}) |
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
31 changes: 31 additions & 0 deletions
31
packages/app/obojobo-express/server/migrations/20240130162639-modify-users-add-last-login.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,31 @@ | ||
'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.addColumn('users', 'last_login', { | ||
type: 'timestamp WITH TIME ZONE', | ||
notNull: true, | ||
defaultValue: new String('now()') | ||
}) | ||
} | ||
|
||
exports.down = function(db) { | ||
return db.removeColumn('last_login') | ||
} | ||
|
||
exports._meta = { | ||
version: 1 | ||
} |
41 changes: 41 additions & 0 deletions
41
packages/app/obojobo-express/server/migrations/20240130163052-create-notification-table.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,41 @@ | ||
'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. | ||
* yarn db:migrateup | ||
*/ | ||
exports.setup = function(options, seedLink) { | ||
dbm = options.dbmigrate | ||
type = dbm.dataType | ||
seed = seedLink | ||
} | ||
|
||
exports.up = function(db) { | ||
return db.createTable('notifications', { | ||
id: { | ||
type: 'bigserial', | ||
primaryKey: true, | ||
notNull: true | ||
}, | ||
created_at: { | ||
type: 'timestamp WITH TIME ZONE', | ||
notNull: true, | ||
defaultValue: new String('now()') | ||
}, | ||
text: { type: 'string', notNull: true }, | ||
title: { type: 'string', notNull: true } | ||
}) | ||
} | ||
|
||
exports.down = function(db) { | ||
db.dropTable('notifications') | ||
} | ||
|
||
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
52 changes: 52 additions & 0 deletions
52
packages/app/obojobo-express/server/viewer/viewer_notification_state.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,52 @@ | ||
const db = oboRequire('server/db') | ||
|
||
function getNotifications(ids) { | ||
if (ids !== 0) { | ||
return db.manyOrNone( | ||
` | ||
SELECT title,text | ||
FROM notifications | ||
WHERE id IN ($[ids:csv]) | ||
ORDER BY id ASC | ||
`, | ||
{ | ||
ids | ||
} | ||
) | ||
} | ||
} | ||
|
||
function getRecentNotifications(date) { | ||
return db.manyOrNone( | ||
` | ||
SELECT id | ||
FROM notifications | ||
WHERE created_at >= $[date] | ||
ORDER BY created_at ASC | ||
`, | ||
{ | ||
date | ||
} | ||
) | ||
} | ||
|
||
function setLastLogin(userId, today) { | ||
return db.none( | ||
` | ||
INSERT INTO users (id, last_login) | ||
VALUES ($[userId], $[today]) | ||
ON CONFLICT (id) DO UPDATE | ||
SET last_login = EXCLUDED.last_login | ||
`, | ||
{ | ||
userId, | ||
today | ||
} | ||
) | ||
} | ||
|
||
module.exports = { | ||
getNotifications, | ||
getRecentNotifications, | ||
setLastLogin | ||
} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
db.removeColumn
takes two arguments, the first being the table name.This should read
return db.removeColumn('users', 'last_login')
.