diff --git a/packages/app/obojobo-express/server/migrations/20240130162639-modify-users-add-last-login.js b/packages/app/obojobo-express/server/migrations/20240506192834-modify-users-add-last-login.js similarity index 91% rename from packages/app/obojobo-express/server/migrations/20240130162639-modify-users-add-last-login.js rename to packages/app/obojobo-express/server/migrations/20240506192834-modify-users-add-last-login.js index 4536813b7..1c1adbca6 100644 --- a/packages/app/obojobo-express/server/migrations/20240130162639-modify-users-add-last-login.js +++ b/packages/app/obojobo-express/server/migrations/20240506192834-modify-users-add-last-login.js @@ -23,7 +23,7 @@ exports.up = function(db) { } exports.down = function(db) { - return db.removeColumn('last_login') + return db.removeColumn('users', 'last_login') } exports._meta = { diff --git a/packages/app/obojobo-express/server/migrations/20240130163052-create-notification-table.js b/packages/app/obojobo-express/server/migrations/20240506193547-create-notification-table.js similarity index 93% rename from packages/app/obojobo-express/server/migrations/20240130163052-create-notification-table.js rename to packages/app/obojobo-express/server/migrations/20240506193547-create-notification-table.js index de4297947..7e3c52d26 100644 --- a/packages/app/obojobo-express/server/migrations/20240130163052-create-notification-table.js +++ b/packages/app/obojobo-express/server/migrations/20240506193547-create-notification-table.js @@ -7,7 +7,6 @@ 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 @@ -33,7 +32,7 @@ exports.up = function(db) { } exports.down = function(db) { - db.dropTable('notifications') + return db.dropTable('notifications') } exports._meta = { diff --git a/packages/app/obojobo-repository/shared/components/notification.test.js b/packages/app/obojobo-repository/shared/components/notification.test.js index 121273a86..b99bdef8a 100644 --- a/packages/app/obojobo-repository/shared/components/notification.test.js +++ b/packages/app/obojobo-repository/shared/components/notification.test.js @@ -18,27 +18,25 @@ describe('Notification component', () => { test('loads notifications from cookies on mount', () => { const onDataFromNotification = jest.fn() - document.cookie = - 'notifications=' + - JSON.stringify([{ key: 1, text: 'Test Notification', title: 'Test Title' }]) + const notificationValue = [{ key: 1, text: 'Test Notification', title: 'Test Title' }] + document.cookie = `notifications=${JSON.stringify(notificationValue)}` const component = create() const tree = component.toJSON() expect(tree).toMatchSnapshot() expect(document.cookie).toBe( - 'notifications=%5B%7B%22key%22%3A1%2C%22text%22%3A%22Test%20Notification%22%2C%22title%22%3A%22Test%20Title%22%7D%5D;' + `notifications=${encodeURIComponent(JSON.stringify(notificationValue))};` ) }) test('handles click on exit button and updates state and cookie', () => { const onDataFromNotification = jest.fn() - document.cookie = - 'notifications=' + - JSON.stringify([ - { key: 1, text: 'Notification1', title: 'Title1' }, - { key: 2, text: 'Notification2', title: 'Title2' } - ]) + const notificationValue = [ + { key: 1, text: 'Notification1', title: 'Title1' }, + { key: 2, text: 'Notification2', title: 'Title2' } + ] + document.cookie = `notifications=${JSON.stringify(notificationValue)}` const reusableComponent = let component @@ -58,11 +56,10 @@ describe('Notification component', () => { exitButtons[key].props.onClick() }) - // Update the tree after state changes tree = component.toJSON() expect(tree).toMatchSnapshot() expect(document.cookie).toBe( - 'notifications=%5B%7B%22key%22%3A2%2C%22text%22%3A%22Notification2%22%2C%22title%22%3A%22Title2%22%7D%5D;' + `notifications=${encodeURIComponent(JSON.stringify(notificationValue))};` ) } }) @@ -136,21 +133,19 @@ describe('Notification component', () => { const tree = component.toJSON() expect(tree).toMatchSnapshot() - if (document && document.cookie) { - //don't get here - } else { - expect(document.cookie).toBe(null) - } + //expect(document.cookie).toBe(null) + document.cookie = originalDocument }) test('does not update cookie when there are no notifications', () => { const onDataFromNotification = jest.fn() - // Ensure notifications state is empty + const notificationValue = [] + document.cookie = `notifications=${JSON.stringify(notificationValue)}` + const component = create() const tree = component.toJSON() - expect(tree).toMatchSnapshot() - // The useEffect should not update the cookie since notifications is empty - expect(document.cookie).toBe('notifications=%5B%5D;') + expect(tree).toMatchSnapshot() + expect(document.cookie).toBe(`notifications=${JSON.stringify(notificationValue)}`) }) }) diff --git a/packages/app/obojobo-repository/shared/components/repository-nav.test.js b/packages/app/obojobo-repository/shared/components/repository-nav.test.js index 8b9367179..faa456938 100644 --- a/packages/app/obojobo-repository/shared/components/repository-nav.test.js +++ b/packages/app/obojobo-repository/shared/components/repository-nav.test.js @@ -230,11 +230,9 @@ describe('RepositoryNav', () => { const tree = component.toJSON() expect(tree).toMatchSnapshot() - if (document && document.cookie) { - //don't get here - } else { - expect(document.cookie).toBe(null) - } + expect(document).not.toBeNull() + expect(document.cookie).toBe(null) + document.cookie = originalDocument }) @@ -305,26 +303,27 @@ describe('RepositoryNav', () => { test('renders null when there are no notifications but document.cookie is not null', () => { const reusableComponent = let component + let parsedValue + const notificationValue = 'otherrandomdata=otherrandomdata' + document.cookie = notificationValue act(() => { component = create(reusableComponent) }) const tree = component.toJSON() expect(tree).toMatchSnapshot() - if (document && document.cookie) { - const cookiePropsRaw = decodeURIComponent(document.cookie).split(';') + expect(document).not.toBeNull() + expect(document.cookie).not.toBeNull() - cookiePropsRaw.forEach(c => { - const parts = c.trim().split('=') + const cookiePropsRaw = decodeURIComponent(document.cookie).split(';') - if (parts[0] === 'notifications') { - //don't get here - } else { - expect(parts[0]).not.toBe('notifications') - } - }) - } else { - expect(document.cookie).toBe('') - } + cookiePropsRaw.forEach(c => { + const parts = c.trim().split('=') + + expect(parts[0]).not.toBe('notifications') + expect(parts[0] === 'notifications').toBe(false) + }) + expect(document.cookie).toBe(notificationValue) + expect(parsedValue).toBe(undefined) }) })