Skip to content
Snippets Groups Projects
Select Git revision
  • 02a58458461fa1d5d6567e03b6cfd71373409612
  • master default protected
  • add-frequency-to-form
  • dev protected
  • ckan-2.11.0
  • add-package-custom-fields
  • fix-adding-datasets-for-users-and-editors
  • add-auth-subroute
  • 71-migrate-custom-fields-to-ckanext-scheming
  • add-author-maintainer-information
  • fix-inline-flex-btns
  • fix-known-spatial-uri-validation
  • py3
  • 47-aktuelle-resource-einer-collection-wird-nicht-mehr-gefunden
  • 10-eingabe-der-dct-accrualperiodicity-in-weboberflache
  • v1.3
  • 2.5.3
  • 2.5.2
  • 2.5.1
  • 2.5.0
  • 2.4.7
  • 2.4.6
  • 2.4.5
  • 2.4.4
  • 2.4.3
  • 2.4.2
  • 2.4.1
  • 2.4.0
  • 2.3.1
  • 2.3.0
  • 2.2.0
  • 2.1.0
  • 2.0.0
  • 1.4.3
  • 1.4.2
  • 1.4.1
36 results

helpers.py

Blame
  • resource.service.spec.ts 18.04 KiB
    import { Mock, mock, useFromMock } from '@alfa-client/test-utils';
    import { Observable, lastValueFrom, of, throwError } from 'rxjs';
    import { ResourceService } from './resource.service';
    import { ResourceRepository } from './resource.repository';
    import { LinkRelationName, ResourceServiceConfig, SaveResourceData } from './resource.model';
    import { Resource, getUrl } from '@ngxp/rest';
    import { createDummyResource } from 'libs/tech-shared/test/resource';
    import {
      StateResource,
      createEmptyStateResource,
      createErrorStateResource,
      createStateResource,
    } from './resource.util';
    import { fakeAsync, tick } from '@angular/core/testing';
    import { singleCold, singleHot } from './marbles';
    import { HttpErrorResponse } from '@angular/common/http';
    import { createProblemDetail } from 'libs/tech-shared/test/error';
    import { HttpError, ProblemDetail } from '../tech.model';
    import { cold } from 'jest-marbles';
    
    import * as ResourceUtil from './resource.util';
    
    describe('ResourceService', () => {
      let service: ResourceService<Resource, Resource>;
      let config: ResourceServiceConfig<Resource>;
    
      let repository: Mock<ResourceRepository>;
    
      const configResource: Resource = createDummyResource();
      const configStateResource: StateResource<Resource> = createStateResource(configResource);
      const configStateResource$: Observable<StateResource<Resource>> = of(configStateResource);
    
      const deleteLinkRel: string = 'dummyDeleteLinkRel';
      const editLinkRel: string = 'dummyEditLinkRel';
      const getLinkRel: LinkRelationName = 'dummyGetLinkRel';
    
      beforeEach(() => {
        config = {
          resource: configStateResource$,
          getLinkRel,
          deleteLinkRel,
          editLinkRel,
        };
        repository = mock(ResourceRepository);
    
        service = new ResourceService(config, useFromMock(repository));
      });
    
      it('should be created', () => {
        expect(service).toBeTruthy();
      });
    
      describe('get', () => {
        const stateResource: StateResource<Resource> = createStateResource(configResource);
    
        beforeEach(() => {
          service.stateResource.next(stateResource);
    
          service.handleNullConfigResource = jest.fn();
          service.handleConfigResource = jest.fn();
          service.handleConfigResourceChanged = jest.fn();
          service.shouldFilter = jest.fn().mockReturnValue(true);
        });
    
        it('should handle config resource changed', fakeAsync(() => {
          service.get().subscribe();
          tick();
    
          expect(service.handleConfigResourceChanged).toHaveBeenCalledWith(configResource);
        }));