This repository has been archived by the owner on Oct 25, 2023. It is now read-only.
/
github.service.spec.ts
76 lines (61 loc) · 2 KB
/
github.service.spec.ts
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { TestBed } from '@angular/core/testing';
import { GithubService } from './github.service';
import { HttpClient } from '@angular/common/http';
import { Release, RepositoryData } from './github-models';
import { of } from 'rxjs';
import { Application } from '../../model/application.model';
describe('GithubService', () => {
let service: GithubService;
const mockHttpClient = {
get: jest.fn(),
};
beforeEach(() => {
TestBed.configureTestingModule({
providers: [{ provide: HttpClient, useValue: mockHttpClient }],
});
service = TestBed.inject(GithubService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
it('should get last release', async () => {
const mockRelease: Release = {
name: 'release name',
};
const repositoryData: RepositoryData = {
repository: 'repo',
username: 'user',
};
mockHttpClient.get.mockReturnValue(of(mockRelease));
const release = await service.getLastRelease(repositoryData);
expect(release).toEqual(mockRelease);
});
it('should get repository data', async () => {
const application: Application = {
id: 'id',
name: 'app',
homepage: 'http://github.com/app-outlet/karavel',
};
const repoData = await service.getRepositoryData(application);
const expected: RepositoryData = {
repository: 'karavel',
username: 'app-outlet',
};
expect(repoData).toEqual(expected);
});
it('should throw error if app has no homepage', (done) => {
const application: Application = {
id: 'id',
name: 'app',
};
service
.getRepositoryData(application)
.then(() => {
fail();
})
.catch((err) => {
expect(err).toBeDefined();
done();
});
});
});