-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug fix on updateUserSession: ensure deepcopy of req.user and adds tests
- Loading branch information
1 parent
10a8d34
commit cf19d02
Showing
5 changed files
with
86 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
const { updateUserSession } = require('./middleware'); | ||
exports.get = (req, res) => { | ||
const { user } = req; | ||
let user = updateUserSession(req); | ||
res.render('profile', { activePage: { profile: true }, user }); | ||
}; |
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,69 @@ | ||
const test = require('tape'); | ||
|
||
const { updateUserSession } = require('../controllers/middleware'); | ||
|
||
test('Test if tape is working', (t) => { | ||
t.ok(true, 'tape is working'); | ||
t.end(); | ||
}); | ||
|
||
// UPDATE USER SESSION | ||
test('Test updateUserSession - registeredProfile: true', (t) => { | ||
const originalRequest = { | ||
user: { | ||
id: 1, | ||
}, | ||
session: { | ||
registeredProfile: true, | ||
} | ||
} | ||
const request = { | ||
user: { | ||
id: 1, | ||
}, | ||
session: { | ||
registeredProfile: true, | ||
} | ||
} | ||
const actual = updateUserSession(request); | ||
const expected = { | ||
id: 1, | ||
session: { | ||
login: true, | ||
signup: false, | ||
} | ||
} | ||
t.deepEquals(actual, expected, 'returns expected result (deepequals)'); | ||
t.deepEquals(request, originalRequest, 'not mutated original request object'); | ||
t.end(); | ||
}); | ||
|
||
test('Test updateUserSession - registeredProfile: false', (t) => { | ||
const originalRequest = { | ||
user: { | ||
id: 1, | ||
}, | ||
session: { | ||
registeredProfile: false, | ||
} | ||
} | ||
const request = { | ||
user: { | ||
id: 1, | ||
}, | ||
session: { | ||
registeredProfile: false, | ||
} | ||
} | ||
const actual = updateUserSession(request); | ||
const expected = { | ||
id: 1, | ||
session: { | ||
login: false, | ||
signup: true, | ||
} | ||
} | ||
t.deepEquals(actual, expected, 'returns expected result (deepequals)'); | ||
t.deepEquals(request, originalRequest, 'not mutated original request object'); | ||
t.end(); | ||
}); |