Skip to content
This repository was archived by the owner on Oct 25, 2023. It is now read-only.

Commit 7fecdc0

Browse files
Messias JuniorMessiasLima
authored andcommitted
test: github service
1 parent f45e50e commit 7fecdc0

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

src/app/service/github/github.service.spec.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ import { TestBed } from '@angular/core/testing';
22

33
import { GithubService } from './github.service';
44
import { HttpClient } from '@angular/common/http';
5+
import { Release, RepositoryData } from './github-models';
6+
import { of } from 'rxjs';
7+
import { Application } from '../../model/application.model';
58

69
describe('GithubService', () => {
710
let service: GithubService;
811

9-
const mockHttpClient = {};
12+
const mockHttpClient = {
13+
get: jest.fn(),
14+
};
1015

1116
beforeEach(() => {
1217
TestBed.configureTestingModule({
@@ -18,4 +23,54 @@ describe('GithubService', () => {
1823
it('should be created', () => {
1924
expect(service).toBeTruthy();
2025
});
26+
27+
it('should get last release', async () => {
28+
const mockRelease: Release = {
29+
name: 'release name',
30+
};
31+
32+
const repositoryData: RepositoryData = {
33+
repository: 'repo',
34+
username: 'user',
35+
};
36+
mockHttpClient.get.mockReturnValue(of(mockRelease));
37+
38+
const release = await service.getLastRelease(repositoryData);
39+
40+
expect(release).toEqual(mockRelease);
41+
});
42+
43+
it('should get repository data', async () => {
44+
const application: Application = {
45+
id: 'id',
46+
name: 'app',
47+
homepage: 'http://github.com/app-outlet/karavel',
48+
};
49+
50+
const repoData = await service.getRepositoryData(application);
51+
52+
const expected: RepositoryData = {
53+
repository: 'karavel',
54+
username: 'app-outlet',
55+
};
56+
57+
expect(repoData).toEqual(expected);
58+
});
59+
60+
it('should throw error if app has no homepage', (done) => {
61+
const application: Application = {
62+
id: 'id',
63+
name: 'app',
64+
};
65+
66+
service
67+
.getRepositoryData(application)
68+
.then(() => {
69+
fail();
70+
})
71+
.catch((err) => {
72+
expect(err).toBeDefined();
73+
done();
74+
});
75+
});
2176
});

0 commit comments

Comments
 (0)