Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then(response => {
expect(response.statusCode).toBe(200);
const expected = {
a: 42,
hello: "world"
};
expect(expected).toEqual(EJSON.parse(response.body!, { relaxed: true }));
// Error responses should be handled
when(transportMock.roundTrip(anything())).thenResolve({
headers: {},
statusCode: 500
});
return stitchRequestClient.doRequest(builder.build());
})
.catch((error: StitchServiceError) => {
before(() => {
account = TestingAccount;
mosaicId = new MosaicId('85BBEA6CC462B244');
mosaicIdWrongKey = new MosaicId('85BBEA6CC462B288');
referenceMosaicId = new MosaicId('1AB129B545561E6A');
const mockRestrictionRepository = mock();
when(mockRestrictionRepository
.getMosaicGlobalRestriction(deepEqual(mosaicId)))
.thenReturn(observableOf(mockGlobalRestriction()));
when(mockRestrictionRepository
.getMosaicGlobalRestriction(deepEqual(mosaicIdWrongKey)))
.thenThrow(new Error());
when(mockRestrictionRepository
.getMosaicAddressRestriction(deepEqual(mosaicId), deepEqual(account.address)))
.thenReturn(observableOf(mockAddressRestriction()));
const restrictionHttp = instance(mockRestrictionRepository);
mosaicRestrictionTransactionService = new MosaicRestrictionTransactionService(restrictionHttp);
});
it("should reject quote when 'rejectQuote' is called", done => {
when(apiService.put(`customers/CID/users/UID/quotes/QID`, anything())).thenReturn(of(undefined));
quoteService.rejectQuote('QID').subscribe(id => {
expect(id).toEqual('QID');
verify(apiService.put(`customers/CID/users/UID/quotes/QID`, anything())).once();
done();
});
});
beforeEach(async(() => {
node = new MapNode();
const selectionManagerMock = mock(SelectionManager);
when(selectionManagerMock.getSelected()).thenReturn([node]);
nodeServiceMock = mock(NodeService);
hotkeyServiceMock = mock(HotkeysService);
hotkeyServiceInstanceMock = instance(hotkeyServiceMock);
TestBed.configureTestingModule({
imports: [HotkeyModule.forRoot(), HttpClientTestingModule],
providers: [
HttpServer,
{ provide: NodeService, useFactory: () => instance(nodeServiceMock) },
{ provide: HotkeysService, useFactory: () => hotkeyServiceInstanceMock },
{ provide: ToasterService, useClass: MockedToasterService },
{ provide: ProjectService, useClass: MockedProjectService },
{ provide: SelectionManager, useValue: instance(selectionManagerMock) },
SettingsService,
MapNodeToNodeConverter,
MapLabelToLabelConverter,
user: { data: { type: 'user', id: 'user02' } },
project: { data: { type: 'project', id: 'project02' } }
}
}),
t.addRecord({
type: 'projectUser',
id: 'projectuser04',
attributes: { role: 'admin', name: 'Project User 4' },
relationships: {
user: { data: { type: 'user', id: 'user02' } },
project: { data: { type: 'project', id: 'project03' } }
}
})
]);
when(this.mockedOrbitService.schema).thenReturn(this.schema);
when(this.mockedOrbitService.store).thenReturn(this.store);
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [
JsonApiService,
{ provide: DomainModel, useValue: domainModel },
{ provide: OrbitService, useFactory: () => instance(this.mockedOrbitService) },
{ provide: JsonRpcService, useFactory: () => instance(this.mockedJsonRpcService) }
]
});
this.service = TestBed.get(JsonApiService);
}
element = fixture.nativeElement;
const translate = TestBed.get(TranslateService);
translate.setDefaultLang('en');
translate.use('en');
translate.setTranslation('en', {
'shopping_cart.ministatus.items.text': { other: '# items' },
'shopping_cart.pli.qty.label': 'x',
'shopping_cart.ministatus.view_cart.link': 'VIEW CART',
});
const lineItem = BasketMockData.getBasketItem();
when(checkoutFacade.basketItemCount$).thenReturn(of(lineItem.quantity.value * 3));
when(checkoutFacade.basketItemTotal$).thenReturn(of(BasketMockData.getTotals().itemTotal));
when(checkoutFacade.basketLineItems$).thenReturn(of([lineItem, lineItem, lineItem]));
when(checkoutFacade.basketError$).thenReturn(EMPTY);
when(checkoutFacade.basketChange$).thenReturn(EMPTY);
});
constructor() {
this.mockedUserService = mock(UserService);
this.mockedNoticeService = mock(NoticeService);
this.mockedSFUserService = mock(SFUserService);
this.mockedJsonApiService = mock(JSONAPIService);
when(this.mockedSFUserService.getAllUserProjects()).thenReturn(of({}));
when(this.mockedSFUserService.onlineAddUser(anything())).thenResolve('projectuser01');
when(this.mockedSFUserService.currentUserId).thenReturn('user01');
TestBed.configureTestingModule({
imports: [
BrowserAnimationsModule,
NoopAnimationsModule,
HttpClientTestingModule,
MatCardModule,
FormsModule,
ReactiveFormsModule,
MatFormFieldModule,
MatIconModule,
MatInputModule,
MatOptionModule,
MatTableModule,
MatDialogModule,
products: [{ sku: 'P1' }, { sku: 'P2' }] as Product[],
total: 2,
})
);
when(productsServiceMock.searchProducts('something', anyNumber(), anything())).thenReturn(
of({ products: [{ sku: 'P2' } as Product], sortKeys: [], total: 1 })
);
promotionsServiceMock = mock(PromotionsService);
when(promotionsServiceMock.getPromotion(anything())).thenReturn(of(promotion));
suggestServiceMock = mock(SuggestService);
when(suggestServiceMock.search('some')).thenReturn(of([{ term: 'something' }]));
filterServiceMock = mock(FilterService);
when(filterServiceMock.getFilterForSearch(anything())).thenReturn(of({} as FilterNavigation));
when(filterServiceMock.getFilterForCategory(anything())).thenReturn(of({} as FilterNavigation));
TestBed.configureTestingModule({
declarations: [DummyComponent],
imports: [
RouterTestingModule.withRoutes([
{
path: 'home',
component: DummyComponent,
},
{
path: 'compare',
component: DummyComponent,
},
{
path: 'error',
})
]
)
);
when(this.mockedUserService.currentUserId).thenReturn('user01');
when(this.mockedAuthService.isLoggedIn).thenResolve(true);
when(this.mockedUserService.getCurrentUser()).thenReturn(of(this.currentUser));
when(
this.mockedUserService.getProjects(
'user01',
deepEqual([[nameof('project'), nameof('texts')]])
)
).thenReturn(this.projects$);
when(this.mockedUserService.updateCurrentProjectId(anything())).thenResolve();
when(this.mockedSFAdminAuthGuard.allowTransition(anything())).thenReturn(of(true));
TestBed.configureTestingModule({
declarations: [AppComponent, MockComponent],
imports: [UICommonModule, DialogTestModule, RouterTestingModule.withRoutes(ROUTES)],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
providers: [
{ provide: AuthService, useFactory: () => instance(this.mockedAuthService) },
{ provide: UserService, useFactory: () => instance(this.mockedUserService) },
{ provide: SFAdminAuthGuard, useFactory: () => instance(this.mockedSFAdminAuthGuard) },
{ provide: SFProjectService, useFactory: () => instance(this.mockedSFProjectService) },
{ provide: RealtimeService, useFactory: () => instance(this.mockedRealtimeService) },
{ provide: LocationService, useFactory: () => instance(this.mockedLocationService) },
{ provide: NoticeService, useFactory: () => instance(this.mockedNoticeService) }
]
});
this.router = TestBed.get(Router);