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

Rebased version of feature/api-v2-auth #142

Merged
merged 57 commits into from Jul 19, 2018
Merged
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
23e1b35
login and set user_id from cookie
trickpattyFH20 Jun 6, 2018
8ecd35a
store cookie and user login info
trickpattyFH20 Jun 7, 2018
db13668
send login data to view
trickpattyFH20 Jun 7, 2018
1ff2067
- add CSRF cookie
trickpattyFH20 Jun 8, 2018
599e4e3
csrf token fix cookie name
trickpattyFH20 Jun 8, 2018
edf35fd
fix return fetch
trickpattyFH20 Jun 8, 2018
3151da8
err handle for missing cookie
trickpattyFH20 Jun 8, 2018
ce7210b
lint
trickpattyFH20 Jun 8, 2018
ce13c38
pull settings
trickpattyFH20 Jun 12, 2018
497549f
v2 loggout
trickpattyFH20 Jul 6, 2018
775e73f
settings conf and fix hanging promise
trickpattyFH20 Jul 10, 2018
c9750f4
pull user settings
trickpattyFH20 Jul 10, 2018
b1ef9a1
move api js from panel to background
trickpattyFH20 Jul 11, 2018
321591d
lint
trickpattyFH20 Jul 11, 2018
6cb0214
Enable log in init from the website.
jsignanini Jul 12, 2018
1ff0dee
Move auth/account domains to globals.
jsignanini Jul 12, 2018
f9cdde2
pull user settings on login and init
trickpattyFH20 Jul 12, 2018
95267b0
lint
trickpattyFH20 Jul 12, 2018
6f3a1c9
Implement logout.
jsignanini Jul 12, 2018
8925f31
Implement send verify email.
jsignanini Jul 12, 2018
ceab22a
login data success missing
trickpattyFH20 Jul 12, 2018
8bc68d9
pushUserSettings and remove unused
trickpattyFH20 Jul 12, 2018
f9ca859
Implement create account v2.
jsignanini Jul 12, 2018
f9353d8
Fix logout from platform pages not sending message to background.
jsignanini Jul 12, 2018
13cb22f
remove api from panel
trickpattyFH20 Jul 12, 2018
1586b4a
Fix missing function.
jsignanini Jul 12, 2018
20027a2
Add error handling for v2 login.
jsignanini Jul 12, 2018
01bc2f3
move userLogin fetch to background
trickpattyFH20 Jul 12, 2018
d6d1cb8
forgot password email
trickpattyFH20 Jul 13, 2018
2bcb36d
fix lgmogout
trickpattyFH20 Jul 13, 2018
a890e69
fix legacy settings conf
trickpattyFH20 Jul 13, 2018
e014e5a
setup login
trickpattyFH20 Jul 13, 2018
170ff18
setup createAccount
trickpattyFH20 Jul 13, 2018
b00d98b
move createAccount fetch
trickpattyFH20 Jul 13, 2018
dc161b6
Several refactors and fixes.
jsignanini Jul 13, 2018
92bba03
Remove catch from logout.
jsignanini Jul 16, 2018
287fcef
account actions unit tests
trickpattyFH20 Jul 16, 2018
96baf39
lint
trickpattyFH20 Jul 16, 2018
785f318
Further refactor.
jsignanini Jul 16, 2018
954d689
Refactor account.register.
jsignanini Jul 16, 2018
3287c98
Refactor send validate account email.
jsignanini Jul 16, 2018
8ab1b9c
Refactor reset password.
jsignanini Jul 17, 2018
77b62e7
More refactoring.
jsignanini Jul 17, 2018
973cbc2
fix unit test
trickpattyFH20 Jul 17, 2018
ec5b159
Linter fix.
jsignanini Jul 17, 2018
a1cf6eb
fix login_info unit tests
trickpattyFH20 Jul 17, 2018
0551439
Add specific babel-loader for background source files.
jsignanini Jul 18, 2018
f3d91e2
refresh token logout handler - api as class
trickpattyFH20 Jul 18, 2018
b803acc
export _getJSONAPIErrorsObject - move getCsrfCookie to api
trickpattyFH20 Jul 18, 2018
03b6630
lint
trickpattyFH20 Jul 18, 2018
0a24cf2
Refactor account into own component.
jsignanini Jul 18, 2018
4ab01fc
Move logged in check into Account class. Cleanup.
jsignanini Jul 18, 2018
b254b0e
Refactor account in setup page.
jsignanini Jul 19, 2018
c96f307
Refactor setup page header log in.
jsignanini Jul 19, 2018
0bafa11
lint - use logger in ExtMessenger
trickpattyFH20 Jul 19, 2018
736afa7
update tests
trickpattyFH20 Jul 19, 2018
c244fb9
Update to be in sync with develop branch
IAmThePan Jul 19, 2018
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

account actions unit tests
  • Loading branch information
trickpattyFH20 authored and IAmThePan committed Jul 19, 2018
commit 287fcef3f1f04750fa153601cd2b2c62e48f37b8
@@ -0,0 +1,173 @@
/**
* Test file for Panel Actions
*
* Ghostery Browser Extension
* https://www.ghostery.com/
*
* Copyright 2018 Ghostery, Inc. All rights reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0
*/

import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import * as msg from '../../utils/msg';
import * as accountActions from '../AccountActions';
import {
LOGIN_FAILED, SHOW_NOTIFICATION, LOGIN_SUCCESS,
GET_SETTINGS_DATA, LOGIN_DATA_SUCCESS
} from '../../constants/constants';

// Fake the translation function to only return the translation key
global.t = function (str) {
return str;
};

const middlewares = [thunk];
const mockStore = configureStore(middlewares);

// TODO mock settings data
const settings = {
};

// TODO mock user data
const user = {
};

// TODO mock user data
const responseSuccess = [
{ 'mockErr': 'error text' }
];

const invalidAccountErr = {
errors: [
{ code: '10050' }
],
};

const serverErr = {
errors: [
{ mockErr: 'server error' }
],
};

msg.sendMessageInPromise = jest.fn((messageType, data) => new Promise((resolve, reject) => {
switch (messageType) {
case 'account.getUserSettings':
resolve(settings);
break;
case 'account.getUser':
resolve(user);
break;
case 'account.login':
if (data.email === 'valid.account') {
resolve(responseSuccess);
} else if (data.email === 'invalid.account') {
resolve(invalidAccountErr);
} else if (data.email === 'server.err') {
resolve(serverErr);
} else {
resolve(responseSuccess);
}
break;
default:
reject();
}
}));

describe('app/panel/actions/AccountActions.js', () => {
test('getUserSettings action should resolve correctly', () => {
const initialState = {};
const store = mockStore(initialState);
const expectedPayload = { data: { settingsData: settings }, type: GET_SETTINGS_DATA };

return store.dispatch(accountActions.getUserSettings()).then(() => {
const actions = store.getActions();
expect(actions).toEqual([expectedPayload]);
});
});
});

describe('app/panel/actions/AccountActions.js', () => {
test('accountGetUser action should resolve correctly', () => {
const initialState = {};
const store = mockStore(initialState);
const expectedPayload = { data: user, type: LOGIN_DATA_SUCCESS };

return store.dispatch(accountActions.accountGetUser()).then(() => {
const actions = store.getActions();
expect(actions).toEqual([expectedPayload]);
});
});

test('accountLogin action valid login should resolve correctly', () => {
const initialState = {};
const store = mockStore(initialState);
const email = 'valid.account';
const password = 'password';
const expectedPayload = [
{
type: LOGIN_SUCCESS
},
{
type: SHOW_NOTIFICATION,
data: {
text: `panel_signin_success ${email}`,
classes: 'success'
}
}
]
return store.dispatch(accountActions.accountLogin(email, password)).then(() => {
const actions = store.getActions();
expect(actions).toEqual(expectedPayload);
});
});

test('accountLogin action invalid account err should fail correctly', () => {
const initialState = {};
const store = mockStore(initialState);
const email = 'invalid.account';
const password = 'password';
const expectedPayload = [
{
type: LOGIN_FAILED
},
{
type: SHOW_NOTIFICATION,
data: {
text: 'banner_no_such_account_message',
classes: 'alert'
}
}
];
return store.dispatch(accountActions.accountLogin(email, password)).then(() => {
const actions = store.getActions();
expect(actions).toEqual(expectedPayload);
});
});

test('accountLogin action server err should fail correctly', () => {
const initialState = {};
const store = mockStore(initialState);
const email = 'server.err';
const password = 'password';
const expectedPayload = [
{
type: LOGIN_FAILED
},
{
type: SHOW_NOTIFICATION,
data: {
text: 'server_error_message',
classes: 'alert'
}
}
]
return store.dispatch(accountActions.accountLogin(email, password)).then(() => {
const actions = store.getActions();
expect(actions).toEqual(expectedPayload);
});
});
});
@@ -0,0 +1,38 @@
/**
* Test file for Panel Actions
*
* Ghostery Browser Extension
* https://www.ghostery.com/
*
* Copyright 2018 Ghostery, Inc. All rights reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0
*/

import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import * as msg from '../../utils/msg';
import * as panelActions from '../PanelActions';
import { TOGGLE_CLIQZ_FEATURE } from '../../constants/constants';

const middlewares = [thunk];
const mockStore = configureStore(middlewares);

describe('app/panel/actions/PanelActions.js', () => {
test('toggleCliqzFeature action should resolve correctly', () => {
const initialState = {};
const store = mockStore(initialState);
const data = {
featureName: 'enable_ad_block',
isEnabled: true
};
const expectedPayload = { data, type: TOGGLE_CLIQZ_FEATURE };

store.dispatch(panelActions.toggleCliqzFeature(data.featureName, data.isEnabled));

const actions = store.getActions();
expect(actions).toEqual([expectedPayload]);
});
});
ProTip! Use n and p to navigate between commits in a pull request.