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

Commit

Permalink
test: github service
Browse files Browse the repository at this point in the history
  • Loading branch information
Messias Junior authored and MessiasLima committed Apr 19, 2021
1 parent f45e50e commit 7fecdc0
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion src/app/service/github/github.service.spec.ts
Expand Up @@ -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({
Expand All @@ -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();
});
});
});

0 comments on commit 7fecdc0

Please sign in to comment.