Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function expectIfCond(card, v1, cond, v2, expectedResult: string, done) {
const templateName = Guid.create().toString();
handlebarsService.executeTemplate(templateName, new DetailContext(card, userContext))
.subscribe((result) => {
console.debug(`testing [${v1} ${cond} ${v2}], result ${result}, expected ${expectedResult}`);
expect(result).toEqual(expectedResult,
`Expected result to be ${expectedResult} when testing [${v1} ${cond} ${v2}]`);
done();
});
let calls = httpMock.match(req => req.url == computeTemplateUri(templateName));
expect(calls.length).toEqual(1);
calls.forEach(call => {
expect(call.request.method).toBe('GET');
call.flush(`{{#if (bool ${v1} "${cond}" ${v2})}}true{{else}}false{{/if}}`);
});
}
it('should create a congruent payload object from AuthObject', () => {
service.assignConfigurationProperties(securityConf);
const guid = Guid.create();
const expirationTime = getPositiveRandomNumberWithinRange(12, 2500);
const authObj = {
identifier: 'rte-operator',
access_token: token,
expires_in: expirationTime,
clientId: guid
} as AuthObject;
const result = service.convert(authObj);
expect(result.token).toEqual(token);
expect(result.identifier).toEqual('rte-operator');
expect(result.clientId).toEqual(guid);
expect(result.expirationDate.getTime()).toBeGreaterThanOrEqual(Date.now() + expirationTime);
});
describe('AuthenticationSelectors', () => {
const referenceDate = new Date();
let emptyAppState: AppState = emptyAppState4Test;
let loadedConfigState: AuthState = {
...authInitialState,
code: 'test-code',
identifier: 'test-user',
clientId: Guid.create(),
token: 'test-token',
expirationDate: referenceDate,
firstName: 'john',
lastName: 'doe'
};
let errorConfigState: AuthState = {
...authInitialState,
message: new Message('this is not working')
};
it('manage empty auth', () => {
let testAppState = {...emptyAppState, authentication: authInitialState};
expect(selectAuthenticationState(testAppState)).toEqual(authInitialState);
expect(selectExpirationTime(testAppState)).toEqual(0);
it('should success if JWT is generated from backend', () => {
const localAction$ = new Actions(hot('-a--', {a: new TryToLogIn({username: 'johndoe', password: 'pwd'})}));
authenticationService.askTokenFromPassword.and.returnValue(of(
new PayloadForSuccessfulAuthentication('johndoe', Guid.create(), 'fake-token', new Date())
));
effects = new AuthenticationEffects(mockStore, localAction$, authenticationService, null, null);
expect(effects).toBeTruthy();
effects.TryToLogIn.subscribe((action: AuthenticationActions) => expect(action.type).toEqual(AuthenticationActionTypes.AcceptLogIn))
});
it('should fail if JWT is not generated from backend', () => {
it('should success if JWT is generated from backend', () => {
const localAction$ = new Actions(hot('-a--', {a: new TryToLogIn({username: 'johndoe', password: 'pwd'})}));
authenticationService.askTokenFromPassword.and.returnValue(of(
new PayloadForSuccessfulAuthentication('johndoe', Guid.create(), 'fake-token', new Date())
));
effects = new AuthenticationEffects(mockStore, localAction$, authenticationService, null, null);
expect(effects).toBeTruthy();
effects.TryToLogIn.subscribe((action: AuthenticationActions) => expect(action.type).toEqual(AuthenticationActionTypes.AcceptLogIn))
});
it('should fail if JWT is not generated from backend', () => {
it('should set items in localStorage when save Authentication Information', () => {
spyOn(localStorage, 'setItem').and.callThrough();
const mockPayload = new PayloadForSuccessfulAuthentication('identifier',
Guid.create(), 'token', new Date());
AuthenticationService.saveAuthenticationInformation(mockPayload);
expect(localStorage.setItem).toHaveBeenCalled();
});
_.forEach(control.pageControlEvents, event => {
events.push({
...event,
id: Guid.create().toString()
})
})
pushHorizontal({ routeName, params, tabIndex = 0, childTabIndex = 0, allowMultipleTransition = false }) {
if (!allowMultipleTransition && this.state.transitionState !== 'noop') {
return;
}
const translateX = new Animated.Value(windowWidth);
const translateY = new Animated.Value(0);
const newScreenHolder = new ScreenHolder(Guid.create().toString(), routeName, this.state.screenHolders.length, routeFromName(this.state.routes, routeName).screen, translateX, translateY, !_.isNil(params) ? params : {}, false, { tabIndex, childTabIndex });
this.setState({
screenHolders: this.state.screenHolders.concat([newScreenHolder]),
transitionState: 'pushing',
});
Animated.timing(translateX, animationConfig(0)).start(() => this.setState({ transitionState: 'noop' }));
}
/** 横移動アニメーションと共にスクリーンを追加表示する。 タブはアニメーションせずに先行表示するので、遷移前スクリーンと遷移後スクリーンが同じタブを使っていると、遷移中にタブをスティッキーに見せることができる。 */
export const initialState = (props: AllProps) => ({
id: Guid.create().toString(),
currentWidth: 0,
currentHeight: 0,
adjustedSize: 0,
spaceTakers: [],
parsedSize: typeof props.anchorSize === "string" ? 0 : props.anchorSize as number | undefined,
left: props.anchor !== AnchorType.Right ? 0 : undefined,
top: props.anchor !== AnchorType.Bottom ? 0 : undefined,
right: props.anchor !== AnchorType.Left ? 0 : undefined,
bottom: props.anchor !== AnchorType.Top ? 0 : undefined,
width: isHorizontalSpace(props) ? props.anchorSize || 0 : undefined,
height: isVerticalSpace(props) ? props.anchorSize || 0 : undefined,
debug: props.debug !== undefined ? props.debug : false,
})
function setStorageWithUserData(expiration?) {
localStorage.setItem(LocalStorageAuthContent.identifier, 'johndoe');
localStorage.setItem(LocalStorageAuthContent.token, 'fake-token');
localStorage.setItem(LocalStorageAuthContent.expirationDate, expiration);
localStorage.setItem(LocalStorageAuthContent.clientId, Guid.create().toString());
}