diff --git a/src/app/service/github/github.service.spec.ts b/src/app/service/github/github.service.spec.ts index 0276eac..64aa257 100644 --- a/src/app/service/github/github.service.spec.ts +++ b/src/app/service/github/github.service.spec.ts @@ -2,11 +2,16 @@ 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 = {}; + const mockHttpClient = { + get: jest.fn(), + }; beforeEach(() => { TestBed.configureTestingModule({ @@ -18,4 +23,54 @@ describe('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(); + }); + }); });