@@ -2,11 +2,16 @@ import { TestBed } from '@angular/core/testing';
2
2
3
3
import { GithubService } from './github.service' ;
4
4
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' ;
5
8
6
9
describe ( 'GithubService' , ( ) => {
7
10
let service : GithubService ;
8
11
9
- const mockHttpClient = { } ;
12
+ const mockHttpClient = {
13
+ get : jest . fn ( ) ,
14
+ } ;
10
15
11
16
beforeEach ( ( ) => {
12
17
TestBed . configureTestingModule ( {
@@ -18,4 +23,54 @@ describe('GithubService', () => {
18
23
it ( 'should be created' , ( ) => {
19
24
expect ( service ) . toBeTruthy ( ) ;
20
25
} ) ;
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
+ } ) ;
21
76
} ) ;
0 commit comments