Skip to content
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

Handle users normalization #1460

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Add more tests
jjpaulino committed Jul 8, 2019
commit 7ab92d2b53f2d7da4475e6951893250f52f97bf3
14 changes: 7 additions & 7 deletions lib/utils/history.test.js
Original file line number Diff line number Diff line change
@@ -26,20 +26,20 @@ describe('history', () => {
test(
'will add the user to the latest event if that event is an edit event',
() => {
const state = { history: [{ action: 'edit', users: [{ username: 'c@d' }] }] },
const state = { history: [{ action: 'edit', users: [{ username: 'c@d', id: 'Y0BkQHVuZGVmaW5lZA==' }] }] },
result = fn(state, currentUser);

expect(result.history[result.history.length - 1].users).toEqual([{username: 'c@d'}, {username: 'a@b', id: 'YUBiQHVuZGVmaW5lZA=='}]);
expect(result.history[result.history.length - 1].users).toEqual([{username: 'c@d', id: 'Y0BkQHVuZGVmaW5lZA=='}, {username: 'a@b', id: 'YUBiQHVuZGVmaW5lZA=='}]);
}
);

test(
'will move the user to be the latest the user is already included',
() => {
const state = { history: [{action: 'edit', users: [{username: 'a@b', id: 'YUBiQHVuZGVmaW5lZA=='}, {username: 'c@d'}]}]},
const state = { history: [{action: 'edit', users: [{username: 'a@b', id: 'YUBiQHVuZGVmaW5lZA=='}, {username: 'c@d', id: 'Y0BkQHVuZGVmaW5lZA=='}]}]},
result = fn(state, currentUser);

expect(result.history[result.history.length - 1].users).toEqual([{username: 'c@d'}, {username: 'a@b', id: 'YUBiQHVuZGVmaW5lZA=='}]);
expect(result.history[result.history.length - 1].users).toEqual([{username: 'c@d', id: 'Y0BkQHVuZGVmaW5lZA=='}, {username: 'a@b', id: 'YUBiQHVuZGVmaW5lZA=='}]);
}
);

@@ -58,7 +58,7 @@ describe('history', () => {

test('will move the user to the end of the array and reset the updateTime if it already exists in the list', () => {
const oldUpdateTime = subMinutes(new Date(), 2).toISOString(),
state = { users: [{ username: 'a@b', id: 'YUBiQHVuZGVmaW5lZA==', updateTime: oldUpdateTime }, { username: 'c@d' }] },
state = { users: [{ username: 'a@b', id: 'YUBiQHVuZGVmaW5lZA==', updateTime: oldUpdateTime }, { username: 'c@d', id: 'Y0BkQHVuZGVmaW5lZA==' }] },
result = fn(state, currentUser);

expect(result.users[result.users.length - 1].username).toBe('a@b');
@@ -79,13 +79,13 @@ describe('history', () => {
currentUser = { username: 'a@b' };

test('returns the last editing user if called less than 5 mins after last update time during a different user\'s session', () => {
const state = { users: [{ username: 'c@d', updateTime: subMinutes(new Date(), 2) }] };
const state = { users: [{ username: 'c@d', id: 'Y0BkQHVuZGVmaW5lZA==', updateTime: subMinutes(new Date(), 2) }] };

expect(fn(state, currentUser).username).toBe('c@d');
});

test('returns undefined if called more than 5 minutes after the last edit', () => {
const state = { users: [{ username: 'c@d', updateTime: subMinutes(new Date(), 6) }] };
const state = { users: [{ username: 'c@d', id: 'Y0BkQHVuZGVmaW5lZA==', updateTime: subMinutes(new Date(), 6) }] };

expect(fn(state, currentUser)).toBeUndefined();
});