Skip to content

Commit

Permalink
migrations regenerated and unit tests updated
Browse files Browse the repository at this point in the history
  • Loading branch information
RachelDau committed May 6, 2024
1 parent d758ecf commit 5dc37a8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,7 +32,7 @@ exports.up = function(db) {
}

exports.down = function(db) {
db.dropTable('notifications')
return db.dropTable('notifications')
}

exports._meta = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(<Notification onDataFromNotification={onDataFromNotification} />)
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 = <Notification onDataFromNotification={onDataFromNotification} />
let component
Expand All @@ -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))};`
)
}
})
Expand Down Expand Up @@ -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(<Notification onDataFromNotification={onDataFromNotification} />)
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)}`)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand Down Expand Up @@ -305,26 +303,27 @@ describe('RepositoryNav', () => {
test('renders null when there are no notifications but document.cookie is not null', () => {
const reusableComponent = <RepositoryNav {...navProps} />
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)
})
})

0 comments on commit 5dc37a8

Please sign in to comment.