Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
serviceMock.callFunction(anything(), anything(), anything())
).times(2);
const [funcNameArg2, funcArgsArg2, resultClassArg2]: any[] = capture(
serviceMock.callFunction
).last();
expect("updateOne").toEqual(funcNameArg2);
expect(1).toEqual(funcArgsArg2.length);
expectedArgs.upsert = true;
expect(expectedArgs).toEqual(funcArgsArg2[0]);
expect(ResultDecoders.remoteUpdateResultDecoder).toEqual(resultClassArg2);
// Should pass along errors
when(
serviceMock.callFunction(anything(), anything(), anything())
).thenReject(new Error("whoops"));
try {
await coll.updateOne({}, {});
fail();
} catch (_) {
// Do nothing
}
});
const requestBody = {
title: movieWithoutId.$title,
releaseYear: movieWithoutId.$releaseYear,
duration: movieWithoutId.$duration,
rating: movieWithoutId.$rating,
seen: movieWithoutId.$seen,
director: {
id: movieWithoutId.$director.$id,
firstName: movieWithoutId.$director.$firstName,
lastName: movieWithoutId.$director.$lastName,
birthYear: movieWithoutId.$director.$birthYear,
},
};
ctx.request.body = requestBody;
when(movieService.save(anything()))
.thenReturn(Promise.resolve(movieWithId));
await controllerUnderTest.saveMovie(ctx);
const [firstArg] = capture(movieService.save).last();
console.log(JSON.stringify(firstArg));
expect(firstArg.$id).equals(undefined);
expect(firstArg.$title).equals(requestBody.title);
expect(firstArg.$releaseYear).equals(requestBody.releaseYear);
expect(firstArg.$duration).equals(requestBody.duration);
expect(firstArg.$rating).equals(requestBody.rating);
expect(firstArg.$seen).equals(requestBody.seen);
expect(firstArg.$director.$id).equals(requestBody.director.id);
expect(firstArg.$director.$firstName).equals(requestBody.director.firstName);
expect(firstArg.$director.$lastName).equals(requestBody.director.lastName);
expect(firstArg.$director.$birthYear).equals(requestBody.director.birthYear);
it('should create and return a new arc primitive.', inject([ArcDrawerService], (service: ArcDrawerService) => {
const arc = service.add(arcProps.geometryProps, arcProps.instanceProps, arcProps.primitiveProps);
verify(primitiveCollection.add(anything())).once();
expect(arc).toBeDefined();
}));
it('should call the quoteService for updateQuoteRequest and for submitQuoteRequest and send an SubmitQuoteRequestFail action on error', done => {
when(quoteRequestServiceMock.submitQuoteRequest(anything())).thenReturn(
throwError({ message: 'something went wrong' })
);
actions$ = of(new quoteRequestActions.UpdateSubmitQuoteRequest({ displayName: 'edited' }));
effects.updateSubmitQuoteRequest$.subscribe(action => {
verify(quoteRequestServiceMock.updateQuoteRequest('QRID', deepEqual({ displayName: 'edited' }))).once();
verify(quoteRequestServiceMock.submitQuoteRequest('QRID')).once();
expect(action).toMatchInlineSnapshot(`
[Quote API] Submit Quote Request Fail:
error: {"message":"something went wrong"}
`);
done();
});
});
});
it('change chapters', fakeAsync(() => {
const env = new TestEnvironment();
env.setTranslateConfig({ selectedTextRef: 'text01', selectedChapter: 1, selectedSegment: 'verse_1_1' });
env.waitForSuggestion();
expect(env.component.chapter).toBe(1);
expect(env.component.target.segmentRef).toBe('verse_1_1');
verify(env.mockedRemoteTranslationEngine.translateInteractively(1, anything())).once();
resetCalls(env.mockedRemoteTranslationEngine);
env.component.chapter = 2;
env.waitForSuggestion();
const verseText = env.component.target.getSegmentText('verse_2_1');
expect(verseText).toBe('target: chapter 2, verse 1.');
expect(env.component.target.segmentRef).toEqual('');
verify(env.mockedRemoteTranslationEngine.translateInteractively(1, anything())).never();
resetCalls(env.mockedRemoteTranslationEngine);
env.component.chapter = 1;
env.waitForSuggestion();
expect(env.component.target.segmentRef).toBe('verse_1_1');
verify(env.mockedRemoteTranslationEngine.translateInteractively(1, anything())).once();
env.dispose();
}));
it('should return error when called with empty category', done => {
categoriesService.getCategory('').subscribe(fail, err => {
expect(err).toBeTruthy();
done();
});
verify(apiServiceMock.get(anything(), anything())).never();
});
it('should add a question if requested', fakeAsync(() => {
const env = new TestEnvironment();
when(env.mockedQuestionDialogRef.afterClosed()).thenReturn(
of({
scriptureStart: 'MAT 3:3',
scriptureEnd: '',
text: ''
})
);
env.fixture.detectChanges();
flush();
verify(env.mockedTextService.getQuestionData(anything())).twice();
resetCalls(env.mockedTextService);
env.clickElement(env.addQuestionButton);
verify(env.mockedMdcDialog.open(anything(), anything())).once();
verify(env.mockedTextService.getQuestionData(anything())).once();
expect().nothing();
}));
});
beforeEach(async(() => {
include = createContentPageletEntryPointView({
id: 'test.include',
definitionQualifiedName: 'test.include-Include',
domain: 'domain',
displayName: 'displayName',
resourceSetId: 'resId',
configurationParameters: {
key: '1',
},
});
cmsFacade = mock(CMSFacade);
when(cmsFacade.contentInclude$(anything())).thenReturn(of(include));
when(cmsFacade.contentIncludeSfeMetadata$(anything())).thenReturn(EMPTY);
TestBed.configureTestingModule({
declarations: [ContentIncludeContainerComponent, MockComponent(ContentPageletContainerComponent)],
providers: [{ provide: CMSFacade, useValue: instance(cmsFacade) }],
}).compileComponents();
}));
userService.signinUserByToken('dummy').subscribe(data => {
verify(apiServiceMock.get(anything(), anything())).once();
const [path, options] = capture(apiServiceMock.get).last();
expect(path).toEqual('customers/-');
expect(options.headers.get(ApiService.TOKEN_HEADER_KEY)).toEqual('dummy');
expect(data).toHaveProperty('user.email', 'test@intershop.de');
done();
});
});
beforeEach(() => {
userServiceMock = mock(UserService);
when(userServiceMock.signinUser(anything())).thenReturn(of(loginResponseData));
when(userServiceMock.createUser(anything())).thenReturn(of(undefined));
when(userServiceMock.updateUser(anything())).thenReturn(of({ firstName: 'Patricia' } as User));
when(userServiceMock.updateUserPassword(anything(), anything(), anything(), anyString())).thenReturn(of(undefined));
when(userServiceMock.updateCustomer(anything())).thenReturn(of(customer));
when(userServiceMock.getCompanyUserData()).thenReturn(of({ firstName: 'Patricia' } as User));
when(userServiceMock.requestPasswordReminder(anything())).thenReturn(of({}));
TestBed.configureTestingModule({
declarations: [DummyComponent],
imports: [
RouterTestingModule.withRoutes([
{ path: 'login', component: DummyComponent },
{ path: 'home', component: DummyComponent },
{ path: 'account', component: DummyComponent },
{ path: 'foobar', component: DummyComponent },
]),
ngrxTesting({ reducers: coreReducers }),