Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (this._cache.groupedList && this._cache.groupedList.length) {
return Observable.of(this._cache.groupedList);
} else if (!this.groupInfos || this.groupInfos.length === 0) {
return Observable.of(this.items)
.do((items) => this._cache.groupedList = items);
} else if (this.items) {
return this.getGroupedList$(this.items)
.do((groupedList) => {
if (this._cache.groupedList && this._cache.groupedList.length && this._cache.groupedList !== groupedList) {
// New grouped list
this.invalidateViewCache();
}
this._cache.groupedList = groupedList;
});
} else {
return Observable.of([]);
}
}
describe('PostEffects', () => {
let effects: PostEffects;
const actions: Observable = Observable.of('');
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
PostEffects,
provideMockActions(() => actions),
// other providers
PostService,
{
provide: Http,
useFactory: (mockBackend, options) => {
return new Http(mockBackend, options);
},
deps: [MockBackend, BaseRequestOptions]
},
MockBackend,
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { mockOperatorMetaData } from './mock-operator-metadata.data';
import { OperatorMetadata, OperatorSchema } from '../../types/operator-schema.interface';
import '../../../common/rxjs-operators';
import { IOperatorMetadataService } from './operator-metadata.service';
@Injectable()
export class StubOperatorMetadataService implements IOperatorMetadataService {
private operatorMetadataObservable = Observable
.of(mockOperatorMetaData)
.shareReplay(1);
constructor() { }
public getOperatorSchema(operatorType: string): OperatorSchema {
const operatorSchema = mockOperatorMetaData.operators.find(schema => schema.operatorType === operatorType);
if (! operatorSchema) {
throw new Error(`can\'t find operator schema of type ${operatorType}`);
}
return operatorSchema;
}
public getOperatorMetadata(): Observable {
return this.operatorMetadataObservable;
}
.catch(err => {
if (err.code === 'PERMISSION_DENIED') {
this.rs.setStatus(401)
return Observable.of({
content: 'unauthorized'
})
} else {
this.rs.setError()
return Observable.of({
content: err || 'server error'
})
}
}))
getName(link: CustomLink): Observable {
return Observable.of(link.redirectTo)
.mergeMap(uri => {
if (uri.startsWith('list/')) {
return this.listService.get(uri.replace('list/', ''));
} else if (uri.startsWith('workshop/')) {
return this.workshopService.get(uri.replace('workshop/', ''));
}
return Observable.of(null)
})
.catch(() => {
return this.customLinkService.remove(link.$key).map(() => null);
})
.filter(val => val !== null)
.map(element => element.name);
}
getLoginState: () => Observable.of(''),
logIn: () => Observable.of({ status : 200 }),
.catch(() => Observable.of(ConnectionError.UNAVAILABLE_BACKEND));
}
const channel: ChatChannel = {
name: 'name',
_id: '123',
server_id: '345',
};
const server: ChatServer = {
name: 'serv',
_id: '345',
owner_id: 'abc',
};
const fakeRoute = {
data: Observable.of({
state: {
channel: Observable.of(channel),
server: Observable.of(server),
me: Observable.of({ _id: 'abc' }),
},
}),
};
const apiServiceMock = {
post: jasmine.createSpy().and.callFake((url: string) => {
if (url.includes('error-generic')) {
const error = { status: 500 };
return Observable.throw(error);
} else if (url.includes('error-with-message')) {
const error = { status: 400, error: { error: 'test' } };
return Observable.throw(error);
}
return Observable.of({}).delay(1);
}),
extractTimeStampInformation() {
return Observable.of(timestampDetails);
},