aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/todo-list-page/todo-list.service.spec.ts
blob: a2ad0cbd7e96b37e0d042b74b17d985217ab953c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { TestBed } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';

import {
  TodoListService, IssueResponse, IssueResponseItem, TodoItem
} from './todo-list.service';
import { toArray } from 'rxjs/operators';


describe('TodoListServiceService', () => {
  beforeEach(() => TestBed.configureTestingModule({
    imports: [HttpClientTestingModule]
  }));

  it('should be created', () => {
    const service: TodoListService = TestBed.get(TodoListService);
    expect(service).toBeTruthy();
  });

  it('should work well', () => {
    const service: TodoListService = TestBed.get(TodoListService);

    const baseUrl = service.baseUrl;

    const mockIssueList: IssueResponse = [{
      number: 1,
      title: 'Issue title 1',
      state: 'open',
      html_url: 'test_url1'
    }, {
      number: 2,
      title: 'Issue title 2',
      state: 'closed',
      html_url: 'test_url2',
      pull_request: {}
    }];

    const mockTodoItemList: TodoItem[] = [{
      number: 1,
      title: 'Issue title 1',
      isClosed: false,
      detailUrl: 'test_url1'
    }];

    service.getWorkItemList().pipe(toArray()).subscribe(data => {
      expect(data).toEqual(mockTodoItemList);
    });

    const httpController: HttpTestingController = TestBed.get(HttpTestingController);

    httpController.expectOne(request => request.url === baseUrl + '/issues' && request.params.get('state') === 'all').flush(mockIssueList);

    httpController.verify();
  });
});