Skip to content

Commit

Permalink
fix: newest release was not considered larger than a beta release
Browse files Browse the repository at this point in the history
  • Loading branch information
cbartel-ci committed Dec 6, 2021
1 parent 189f354 commit 9817d3d
Show file tree
Hide file tree
Showing 11 changed files with 235 additions and 18 deletions.
67 changes: 67 additions & 0 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
"start:dev": "nest start --watch -- --dataPath \"./../data/\" --development",
"start:debug": "nest start --debug --watch -- --dataPath \"./../data/\" --development",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
"test": "jest --config test/jest.config.json",
"test:watch": "jest --config test/jest.config.json --watch",
"test:cov": "jest --config test/jest.config.json --coverage",
"test:debug": "node --config test/jest.config.json --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config test/jest.config-e2e.json"
},
"dependencies": {
"@nestjs/axios": "^0.0.3",
Expand Down Expand Up @@ -74,6 +74,7 @@
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.2.5",
"nock": "^13.2.1",
"prettier": "^2.3.2",
"source-map-support": "^0.5.20",
"supertest": "^6.1.3",
Expand Down
8 changes: 3 additions & 5 deletions server/src/github/github.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ export class GithubService {

public async getLatestBetaRelease(): Promise<GithubRelease> {
const releases = await this.getReleases();
return releases
.filter((release) => release.prerelease)
.reduce((previousValue, currentValue) =>
semver.gt(previousValue.name.substring(1), currentValue.name.substring(1)) ? previousValue : currentValue,
);
return releases.reduce((previousValue, currentValue) =>
semver.gt(previousValue.name.substring(1), currentValue.name.substring(1)) ? previousValue : currentValue,
);
}

public getReleases(): Promise<GithubRelease[]> {
Expand Down
9 changes: 3 additions & 6 deletions server/test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { AppModule } from './../src/app.module';
import request from 'supertest';
import { AppModule } from '../src/app.module';

describe('AppController (e2e)', () => {
let app: INestApplication;
Expand All @@ -16,9 +16,6 @@ describe('AppController (e2e)', () => {
});

it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!');
return request(app.getHttpServer()).get('/').expect(200).expect('Hello World!');
});
});
52 changes: 52 additions & 0 deletions server/test/github/data/releases-newest-is-beta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[
{
"name": "v1.0.0-beta.1",
"prerelease": true,
"assets": [
{
"label": "node distribution",
"browser_download_url": "some_url"
}
]
},
{
"name": "v1.0.0-beta.2",
"prerelease": true,
"assets": [
{
"label": "node distribution",
"browser_download_url": "some_url"
}
]
},
{
"name": "v1.0.0-beta.3",
"prerelease": true,
"assets": [
{
"label": "node distribution",
"browser_download_url": "some_url"
}
]
},
{
"name": "v1.0.0",
"prerelease": false,
"assets": [
{
"label": "node distribution",
"browser_download_url": "some_url"
}
]
},
{
"name": "v1.1.0-beta.1",
"prerelease": false,
"assets": [
{
"label": "node distribution",
"browser_download_url": "some_url"
}
]
}
]
42 changes: 42 additions & 0 deletions server/test/github/data/releases.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"name": "v1.0.0-beta.1",
"prerelease": true,
"assets": [
{
"label": "node distribution",
"browser_download_url": "some_url"
}
]
},
{
"name": "v1.0.0-beta.2",
"prerelease": true,
"assets": [
{
"label": "node distribution",
"browser_download_url": "some_url"
}
]
},
{
"name": "v1.0.0-beta.3",
"prerelease": true,
"assets": [
{
"label": "node distribution",
"browser_download_url": "some_url"
}
]
},
{
"name": "v1.0.0",
"prerelease": false,
"assets": [
{
"label": "node distribution",
"browser_download_url": "some_url"
}
]
}
]
38 changes: 38 additions & 0 deletions server/test/github/github.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import nock from 'nock';

import releases from './data/releases.json';
import releasesBeta from './data/releases-newest-is-beta.json';
import { GithubModule } from '../../src/github/github.module';
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { GithubService } from '../../src/github/github.service';

describe('GitHub Service', () => {
let app: INestApplication;

beforeEach(async () => {
nock.cleanAll();
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [GithubModule],
}).compile();

app = moduleFixture.createNestApplication();
await app.init();
});

it('should return correct latest release version if there is no older beta release', async () => {
nock('https://api.github.com/').get('/repos/cbartel/nw-company-tool/releases').reply(200, JSON.stringify(releases));
const githubService = app.get(GithubService);
const latestBetaRelease = await githubService.getLatestBetaRelease();
expect(latestBetaRelease.name).toEqual('v1.0.0');
});

it('should return correct latest beta release version', async () => {
nock('https://api.github.com/')
.get('/repos/cbartel/nw-company-tool/releases')
.reply(200, JSON.stringify(releasesBeta));
const githubService = app.get(GithubService);
const latestBetaRelease = await githubService.getLatestBetaRelease();
expect(latestBetaRelease.name).toEqual('v1.1.0-beta.1');
});
});
17 changes: 17 additions & 0 deletions server/test/jest.config-e2e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": "\\.e2e-spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"moduleNameMapper": {
"@nw-company-tool/model/(.*)": "<rootDir>/../libs/model/src/$1",
"@nw-company-tool/model": "<rootDir>/../libs/model/src"
}
}
4 changes: 2 additions & 2 deletions server/test/jest-e2e.json → server/test/jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"testRegex": "\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"moduleNameMapper": {
"@nw-company-tool/model/(.*)": "<rootDir>/../libs/model/src/$1",
"@nw-company-tool/model": "<rootDir>/../libs/model/src"
}
}
}
1 change: 1 addition & 0 deletions server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"outDir": "./dist",
"baseUrl": "./",
"esModuleInterop": true,
"resolveJsonModule": true,
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
Expand Down
4 changes: 4 additions & 0 deletions server/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"include": [ "test", "**/*spec.ts"]
}

0 comments on commit 9817d3d

Please sign in to comment.