Skip to content

Commit

Permalink
Add/unit tests (#10)
Browse files Browse the repository at this point in the history
* added git api unit test

* consistant styling
  • Loading branch information
hoonsubin authored Nov 5, 2020
1 parent d4a887d commit 526d732
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 18 deletions.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
"typescript",
"cli-tool"
],
"main": "lib/index.js",
"module": "lib/index.js",
"bin": {
"glitch-deploy-tool": "lib/cli/index.js"
},
"private": false,
"homepage": "https://github.com/TeamSTEP/glitch-deploy-tool",
"bugs": {
Expand All @@ -27,10 +32,6 @@
"darwin",
"linux"
],
"module": "lib/index.js",
"bin": {
"glitch-deploy-tool": "lib/cli/index.js"
},
"scripts": {
"start": "NODE_ENV=production ts-node -r dotenv/config src/index.ts",
"dev": "NODE_ENV=development ts-node-dev -r dotenv/config src/index.ts",
Expand Down
3 changes: 0 additions & 3 deletions src/helpers/addNumber.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './addNumber';
export * from './fileUtils';
53 changes: 53 additions & 0 deletions tests/glitchApi.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { GlitchProject } from '../src';
import nock from 'nock';

describe('Importing Github repositories to Glitch', () => {
// set up a mock token and query params for the test
const token = '7dd3b76-a13c-a13c-a13c-152b3539bdcd';
const projectId = '8c28b8-9db3-6098-1ab2-54e70d3347b4';
const repo = 'userorg/project';
const path = 'build';

beforeEach(() => {
nock.disableNetConnect();
});

it('imports the given repo to Glitch with a status 200', async () => {
nock('https://api.glitch.com')
.post('/project/githubImport')
.query({
authorization: token,
projectId,
repo,
path,
})
.reply(200, { status: 200 });

const glitchApi = new GlitchProject(token, projectId);
const response = await glitchApi.importFromGithub(repo, path);
expect(response.status).toBe(200);
});

it('imports the given repo with a subdirectory in the parameter', async () => {
nock('https://api.glitch.com')
.post('/project/githubImport')
.query({
authorization: token,
projectId,
repo,
path: '/', // default path
})
.reply(200, { status: 200 });

const glitchApi = new GlitchProject(token, projectId);
const response = await glitchApi.importFromGithub(repo);
expect(response.status).toBe(200);
});

afterEach(() => {
nock.cleanAll();
nock.enableNetConnect();
});

//todo: add a unit test for GlitchGit class
});
10 changes: 0 additions & 10 deletions tests/sample.test.ts

This file was deleted.

0 comments on commit 526d732

Please sign in to comment.