Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it(`should navigate to Home`, () => {
// Given
const wrapper = mount(
)
const createCrowdsaleComponentWrapper = wrapper.find(CreateCrowdsale)
const instance = createCrowdsaleComponentWrapper.instance()
const goToStepOneHandler = jest.spyOn(instance, 'goToStepOne')
instance.forceUpdate()
// When
storage.set('DeploymentStore', { deploymentStep: 1 })
const buttonCreateCrowdsale = createCrowdsaleComponentWrapper.find('.hm-Home_BtnNew')
buttonCreateCrowdsale.simulate('click')
// Then
expect(buttonCreateCrowdsale.length).toBe(1)
expect(goToStepOneHandler).toHaveBeenCalledTimes(1)
expect(goToStepOneHandler).toHaveBeenCalledWith()
})
it(`should navigate to Crowdsales List`, async () => {
// Given
const wrapper = mount(
)
const chooseCrowdsaleComponentWrapper = wrapper.find(ChooseCrowdsale)
const instance = chooseCrowdsaleComponentWrapper.instance()
const goToCrowdsalesHandler = jest.spyOn(instance, 'goToCrowdsales')
instance.forceUpdate()
storage.clearAll()
// When
const chooseCrowdsale = chooseCrowdsaleComponentWrapper.find('.hm-Home_BtnChoose')
chooseCrowdsale.simulate('click')
// Then
expect(chooseCrowdsale.length).toBe(1)
expect(goToCrowdsalesHandler).toHaveBeenCalledTimes(1)
expect(goToCrowdsalesHandler).toHaveBeenCalledWith()
})
})
it('should be able to login successfully', inject(['AuthService','$httpBackend','$rootScope', function( AuthService, $httpBackend, $rootScope ) {
$httpBackend.whenPOST('user/authenticate', null).respond( 200, 'Done' );
$httpBackend.whenGET('user/authenticated/retrieve').respond( {"password":null,"username":"user","authorities":[{"authority":"ROLE_USER"}],"accountNonExpired":true,"accountNonLocked":true,"credentialsNonExpired":true,"enabled":true});
var spy = sinon.spy($rootScope, "$emit");
var spy2 = sinon.spy($rootScope, '$broadcast');
AuthService.login( $rootScope, "user", "user" );
expect(spy).to.have.been.calledWith("event:loginRequest");
$rootScope.$apply();
$httpBackend.flush();
// Verify login function
expect(spy2).to.have.been.calledWith("event:loginConfirmed");
expect(store.session.get("userInfo")).not.to.be.null;
expect($rootScope.user).not.to.be.null;
expect($rootScope.userInfo).not.to.be.null;
// Verify isLoggedIn function
expect(AuthService.isLoggedIn()).to.be.true;
// Verify logout function
AuthService.logout( $rootScope ).then(function() {
expect(store.session.get("userInfo")).to.be.null;
expect(spy).to.have.been.calledWith("event:logoutRequest");
expect($rootScope.user).to.be.null;
expect($rootScope.userInfo).to.be.null;
});
}]));
.then(function(results) {
// console.log("results[1] ", results[ 1 ] );
if( results[ 1 ] )
{
$rootScope.user = results[ 1 ].data;
var userInfo = {
authorities: results[ 1 ].data.authorities,
userName: results[ 1 ].data.username
};
store.session.set( "userInfo", angular.toJson( userInfo ) );
$rootScope.userInfo = userInfo;
// console.log("Got the user to be ", user );
$rootScope.$broadcast('event:loginConfirmed');
delete $rootScope.error;
}
deferred.resolve(results[1].data);
},
function(error) {
export default function persistFactory(ns, persistMutations) {
const storage = Storage.namespace(ns);
return function(store) {
// Reusable so we can trigger now and attach to focus event
const load = () => {
persistMutations.forEach(mutation => {
if (storage.has(mutation)) {
const payloads = /^ADD/.test(mutation) ? storage(mutation) : [storage(mutation)];
payloads.forEach(payload => store.commit(mutation, payload));
}
});
};
window.addEventListener('focus', load);
load();
import PricingStrategyStore from './PricingStrategyStore';
import ReservedTokenStore from './ReservedTokenStore';
import StepTwoValidationStore from './StepTwoValidationStore';
import TierStore from './TierStore';
import TokenStore from './TokenStore';
import Web3Store from './Web3Store';
import GeneralStore from './GeneralStore'
import CrowdsalePageStore from './CrowdsalePageStore'
import InvestStore from './InvestStore'
import CrowdsaleStore from './CrowdsaleStore'
import GasPriceStore from './GasPriceStore'
import DeploymentStore from './DeploymentStore'
import StatsStore from './StatsStore'
// Clear local storage if there is no incomplete deployment
if (storage.has('DeploymentStore') && storage.get('DeploymentStore').deploymentStep === null) {
localStorage.clear()
}
const generalStore = new GeneralStore()
const crowdsalePageStore = new CrowdsalePageStore()
const contractStore = new ContractStore()
const pricingStrategyStore = new PricingStrategyStore()
const reservedTokenStore = new ReservedTokenStore()
const stepTwoValidationStore = new StepTwoValidationStore()
const tierStore = new TierStore()
const tokenStore = new TokenStore()
const web3Store = new Web3Store()
const investStore = new InvestStore()
const crowdsaleStore = new CrowdsaleStore()
const gasPriceStore = new GasPriceStore()
const deploymentStore = new DeploymentStore()
checkForCode() {
const query = queryString.parse(location.hash.substr(1));
if (query.code && !localstorage('accessToken')) {
localstorage({
accessToken: query.access_token,
expiresIn: query.expires_in,
idToken: query.id_token,
tokenType: query.token_type,
});
this.setState(localstorage());
history.replace('/');
} else if (localstorage('accessToken')) {
this.setState(localstorage());
}
}
checkForCode() {
const query = queryString.parse(location.hash.substr(1));
if (query.code && !localstorage('accessToken')) {
localstorage({
accessToken: query.access_token,
expiresIn: query.expires_in,
idToken: query.id_token,
tokenType: query.token_type,
});
this.setState(localstorage());
history.replace('/');
} else if (localstorage('accessToken')) {
this.setState(localstorage());
}
}
checkForCode() {
const query = queryString.parse(location.hash.substr(1));
if (query.code && !localstorage('accessToken')) {
localstorage({
accessToken: query.access_token,
expiresIn: query.expires_in,
idToken: query.id_token,
tokenType: query.token_type,
});
this.setState(localstorage());
history.replace('/');
} else if (localstorage('accessToken')) {
this.setState(localstorage());
}
}
submitForm(e) {
e.preventDefault();
const data = new FormData();
fields.forEach(({id}) => data.append(id, this.state[id]));
const file = this.pictureUpload.files[0];
if (file) {
data.append('picture', file, file.name);
}
const headers = new Headers();
headers.append('Authorization', `Bearer ${localstorage('accessToken')}`);
fetch(`${config.identityServer}api/user/profile`, {
method: 'PUT',
headers,
body: data,
}).then((res) => res.json())
.then((data) => {
this.setState({ showMessage: true, message: 'Profile Updated' });
setTimeout(() => {
this.setState({
...defaultFields,
showMessage: false,
message: '',
picture: '',
});
}, 1000);