Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('applyLazyLoadEvent() top and skip', () => {
// Assign
const loadEvent: LazyLoadEvent = {
rows: 11,
first: 12
};
// Act
const query = new ODataQuery<Employee>('Employees', config, undefined);
spyOn(query, 'Top').and.returnValue(query);
spyOn(query, 'Skip').and.returnValue(query);
PrimeNGDataTableODataQueryExtensions.applyLazyLoadEvent(query, loadEvent);
// Assert
expect(query.Top).toHaveBeenCalledWith(11);
expect(query.Skip).toHaveBeenCalledWith(12);
});
it('applyLazyLoadEvent() multiSortMeta', () => {
// Assign
const loadEvent: LazyLoadEvent = {
multiSortMeta: [
{ field: 'Name', order: 1 },
{ field: 'Last', order: 0 }
]
};
// Act
const query = new ODataQuery<Employee>('Employees', config, undefined);
spyOn(query, 'OrderBy').and.returnValue(query);
PrimeNGDataTableODataQueryExtensions.applyLazyLoadEvent(query, loadEvent);
// Assert
expect(query.OrderBy).toHaveBeenCalledWith('Name asc, Last desc');
});
it('applyLazyLoadEvent() contains', () => {
// Assign
const loadEvent: LazyLoadEvent = {
filters: {
'Name': { 'value': 'abc', 'matchMode': 'contains' }
}
};
// Act
const query = new ODataQuery<Employee>('Employees', config, undefined);
spyOn(query, 'Filter');
PrimeNGDataTableODataQueryExtensions.applyLazyLoadEvent(query, loadEvent);
// Assert
expect(query.Filter).toHaveBeenCalledWith('contains(Name, \'abc\')');
});
it('applyLazyLoadEvent.Exec', inject([HttpClient, ODataConfiguration], (http: HttpClient, cfg: ODataConfiguration) => {
// Assign
const loadEvent: LazyLoadEvent = {
filters: {
'X': { 'value': '123', 'matchMode': 'eq' },
'Boss.Country.Name': { 'value': `'USA'`, 'matchMode': 'eq' }
}
};
spyOn(http, 'get').and.returnValue(Observable.of(Response));
// Act
const query = new ODataQuery<Employee>('Employees', cfg, http);
PrimeNGDataTableODataQueryExtensions.applyLazyLoadEvent(query, loadEvent);
query.Exec();
const getOptions: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
} = { params: new HttpParams().append('$filter', `X eq 123 and Boss/Country/Name eq 'USA'`), observe: 'response' };
expect(http.get).toHaveBeenCalledWith('http://localhost/odata/Employees', getOptions);
}));
describe('PrimeNGDataTableODataQueryExtensions', () => {
const config = new ODataConfiguration();
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
BaseRequestOptions,
ODataConfiguration
],
imports: [
HttpClientTestingModule
]
});
});
it('applyLazyLoadEvent() top and skip', () => {
// Assign
const loadEvent: LazyLoadEvent = {
constructor () {
const config = new ODataConfiguration();
config.baseUrl = 'https://odatateststef.azurewebsites.net/odata';
return config;
}
}