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

Commit

Permalink
Added coverall
Browse files Browse the repository at this point in the history
  • Loading branch information
ziccardi committed Mar 30, 2020
1 parent a8c633a commit fade552
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 141 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/build.yml
@@ -1,13 +1,17 @@
name: Build the library
name: build

on: [push]
on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v1
with:
node-version: '10.x'

- name: Install dependencies
run: npm install

Expand All @@ -18,4 +22,9 @@ jobs:
run: npm run compile

- name: Test
run: npm run test
run: npm run test

- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,3 +2,4 @@ node_modules
build
dist
.idea
coverage
3 changes: 3 additions & 0 deletions README.md
@@ -1,5 +1,8 @@
# UnifiedPush Server Admin Client

![Build](https://github.com/aerogear/unifiedpush-admin-client/workflows/build/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/aerogear/unifiedpush-admin-client/badge.svg)](https://coveralls.io/github/aerogear/unifiedpush-admin-client)

The _UnifiedPush Server Admin_ library allows to admin the UPS by javascript or typescript code.

## Getting started
Expand Down
9 changes: 7 additions & 2 deletions jest.config.js
@@ -1,5 +1,10 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
rootDir: 'test'
};
collectCoverage: true,
collectCoverageFrom: ['src/**/*.ts'],
roots: [
'test',
'src'
]
};
7 changes: 7 additions & 0 deletions package.json
Expand Up @@ -34,5 +34,12 @@
},
"dependencies": {
"axios": "0.19.2"
},
"repository": {
"type": "git",
"url": "git+https://github.com/aerogear/unifiedpush-admin-client.git"
},
"bugs": {
"url": "https://github.com/aerogear/unifiedpush-admin-client/issues"
}
}
28 changes: 0 additions & 28 deletions src/main.ts

This file was deleted.

107 changes: 107 additions & 0 deletions test/UnifiedPushAdminClient.test.ts
@@ -0,0 +1,107 @@
import axios from 'axios';
import { mockData } from './mockData';
import { PushApplication, UnifiedPushAdminClient } from '../src';
import { mocked } from 'ts-jest/dist/util/testing';

jest.mock('axios');

const mockedAxios = axios as jest.Mocked<typeof axios>;

mocked(axios).create = () => mockedAxios;

const upsClient = new UnifiedPushAdminClient('http://localhost:9999');

describe('Applications Admin', () => {
it('test find without filters', async () => {
mockedAxios.get.mockImplementationOnce(() => Promise.resolve({ data: mockData }));

const res = await new UnifiedPushAdminClient('http://localhost:9999').applications.find();
expect(res).toHaveLength(mockData.length);
expect(mockedAxios.get).toHaveBeenCalledWith('/applications');
});
it('test find with single filter', async () => {
mockedAxios.get.mockImplementationOnce(() => Promise.resolve({ data: mockData }));

const res = await new UnifiedPushAdminClient('http://localhost:9999').applications.find({
developer: 'Test Developer 2',
});
expect(res).toHaveLength(2);
expect(mockedAxios.get).toHaveBeenCalledWith('/applications');
});
it('test find with multiple filter', async () => {
mockedAxios.get.mockImplementationOnce(() => Promise.resolve({ data: mockData }));

const res = await new UnifiedPushAdminClient('http://localhost:9999').applications.find({
developer: 'Test Developer 2',
name: 'Application 4',
});
expect(res).toHaveLength(1);
expect(res[0].name).toEqual('Application 4');
expect(mockedAxios.get).toHaveBeenCalledWith('/applications');
});

it('test create app', async () => {
const appToBeCreated = mockData[3];
mockedAxios.post.mockImplementationOnce((url: string, app: PushApplication) => Promise.resolve({ data: app }));

const res = await new UnifiedPushAdminClient('http://localhost:9999').applications.create(appToBeCreated);
expect(res).toEqual(appToBeCreated);
expect(mockedAxios.post).toHaveBeenCalledWith('/applications', appToBeCreated);
});
});

describe('Variants Admin', () => {
it('test find without filters', async () => {
const appId = '1';
const selectedApp = mockData.filter(app => app.id === appId)[0];
mockedAxios.get.mockImplementationOnce(() => Promise.resolve({ data: selectedApp }));

const res = await upsClient.variants.find(appId);
expect(res).toHaveLength(selectedApp!.variants!.length);
expect(mockedAxios.get).toHaveBeenCalledWith(`/applications/${appId}`);
});

it('test find with single filter', async () => {
const appId = '1';
const selectedApp = mockData.filter(app => app.id === appId)[0];
mockedAxios.get.mockImplementation(() => Promise.resolve({ data: selectedApp }));

let res = await upsClient.variants.find(appId, { developer: 'developer 2' });
expect(res).toHaveLength(1);
expect(mockedAxios.get).toHaveBeenCalledWith(`/applications/${appId}`);

res = await upsClient.variants.find(appId, { developer: 'developer 1' });
expect(res).toHaveLength(2);
expect(mockedAxios.get).toHaveBeenCalledWith(`/applications/${appId}`);
});

it('test find one variant/no filters', async () => {
const appId = '3';
const selectedApp = mockData.filter(app => app.id === appId)[0];
mockedAxios.get.mockImplementation(() => Promise.resolve({ data: selectedApp }));

const res = await upsClient.variants.find(appId);
expect(res).toHaveLength(1);
expect(mockedAxios.get).toHaveBeenCalledWith(`/applications/${appId}`);
});

it('test find with bad filter', async () => {
const appId = '1';
const selectedApp = mockData.filter(app => app.id === appId)[0];
mockedAxios.get.mockImplementation(() => Promise.resolve({ data: selectedApp }));

const res = await upsClient.variants.find(appId, { developer: 'developer 84' });
expect(res).toHaveLength(0);
expect(mockedAxios.get).toHaveBeenCalledWith(`/applications/${appId}`);
});

it('test app without variants', async () => {
const appId = '4';
const selectedApp = mockData.filter(app => app.id === appId)[0];
mockedAxios.get.mockImplementation(() => Promise.resolve({ data: selectedApp }));

const res = await upsClient.variants.find(appId, { developer: 'developer 84' });
expect(res).toHaveLength(0);
expect(mockedAxios.get).toHaveBeenCalledWith(`/applications/${appId}`);
});
});
45 changes: 0 additions & 45 deletions test/applications/ApplicationAdmin.test.ts

This file was deleted.

63 changes: 0 additions & 63 deletions test/variants/VariantsAdmin.test.ts

This file was deleted.

0 comments on commit fade552

Please sign in to comment.