Skip to content

Commit

Permalink
Merge pull request #7 from technote-space/release/v0.0.9
Browse files Browse the repository at this point in the history
Release/v0.0.9
  • Loading branch information
technote-space committed Sep 26, 2019
2 parents 4d279c5 + a32f6fc commit b410999
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 8 deletions.
62 changes: 61 additions & 1 deletion __tests__/context.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-magic-numbers */
import { getContext, createResponse } from '../src';
import { getContext, generateContext, createResponse } from '../src';

describe('getContext', () => {
it('should get context', () => {
Expand All @@ -22,6 +22,66 @@ describe('getContext', () => {
});
});

describe('generateContext', () => {
it('should generate context 1', () => {
const context = generateContext({});
expect(context.eventName).toBe('');
expect(context.payload.action).toBe('');
expect(context.ref).toBe('');
expect(context.sha).toBe('');
expect(context.issue.owner).toBe('');
expect(context.repo.owner).toBe('');
expect(context.issue.repo).toBe('');
expect(context.repo.repo).toBe('');
});

it('should generate context 2', () => {
const context = generateContext({
event: 'test-event',
action: 'test-action',
ref: 'test-ref',
sha: 'test-sha',
owner: 'test-owner',
repo: 'test-repo',
});
expect(context.eventName).toBe('test-event');
expect(context.payload.action).toBe('test-action');
expect(context.ref).toBe('refs/test-ref');
expect(context.sha).toBe('test-sha');
expect(context.issue.owner).toBe('test-owner');
expect(context.repo.owner).toBe('test-owner');
expect(context.issue.repo).toBe('test-repo');
expect(context.repo.repo).toBe('test-repo');
});

it('should override', () => {
const context = generateContext({
event: 'test-event',
action: 'test-action',
ref: 'test-ref',
sha: 'test-sha',
owner: 'test-owner',
repo: 'test-repo',
}, {
eventName: 'override-event',
ref: 'override-ref',
sha: 'override-sha',
repo: {
owner: 'override-owner',
repo: 'override-repo',
},
});
expect(context.eventName).toBe('override-event');
expect(context.payload.action).toBe('test-action');
expect(context.ref).toBe('override-ref');
expect(context.sha).toBe('override-sha');
expect(context.issue.owner).toBe('test-owner');
expect(context.repo.owner).toBe('override-owner');
expect(context.issue.repo).toBe('test-repo');
expect(context.repo.repo).toBe('override-repo');
});
});

describe('createResponse', () => {
it('should create response', () => {
const response = createResponse<number>(123);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@technote-space/github-action-test-helper",
"version": "0.0.8",
"version": "0.0.9",
"description": "Test helper for GitHub Action.",
"author": "Technote <technote.space@gmail.com> (https://technote.space)",
"license": "MIT",
Expand Down
19 changes: 19 additions & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,25 @@ export const getContext = (override: object): Context => Object.assign({
},
}, override);

export const generateContext = (settings: { event?: string; action?: string; ref?: string; sha?: string; owner?: string; repo?: string }, override?: object): Context => getContext(
Object.assign({
eventName: settings.event ? settings.event : '',
payload: {
action: settings.action ? settings.action : '',
},
ref: settings.ref ? `refs/${settings.ref}` : '',
sha: settings.sha ? settings.sha : '',
issue: {
owner: settings.owner ? settings.owner : '',
repo: settings.repo ? settings.repo : '',
},
repo: {
owner: settings.owner ? settings.owner : '',
repo: settings.repo ? settings.repo : '',
},
}, override || {}),
);

type CreateResponseFunctionType = <T>(data: T, override?: object) => Response<T>;
export const createResponse: CreateResponseFunctionType = (data, override = {}) => Object.assign({
data,
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2724,9 +2724,9 @@ minipass@^2.9.0:
yallist "^3.0.0"

minizlib@^1.2.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/minizlib/-/minizlib-1.3.1.tgz#7335640a57f584320b4fcf41069082c442bc6bf7"
integrity sha512-8AgjrT7C8U/HQWM+02YJHLPh4BypAhc5pFddr0nCcowNy1Hj0hmKPMq9WkjBMn0rtUg3ia30MkCexdd1pTiTIA==
version "1.3.2"
resolved "https://registry.yarnpkg.com/minizlib/-/minizlib-1.3.2.tgz#5d24764998f98112586f7e566bd4c0999769dad4"
integrity sha512-lsNFqSHdJ21EwKzCp12HHJGxSMtHkCW1EMA9cceG3MkMNARjuWotZnMe3NKNshAvFXpm4loZqmYsCmRwhS2JMw==
dependencies:
minipass "^2.9.0"

Expand Down Expand Up @@ -4184,9 +4184,9 @@ y18n@^4.0.0:
integrity sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==

yallist@^3.0.0, yallist@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.0.3.tgz#b4b049e314be545e3ce802236d6cd22cd91c3de9"
integrity sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==
version "3.1.0"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.0.tgz#906cc2100972dc2625ae78f566a2577230a1d6f7"
integrity sha512-6gpP93MR+VOOehKbCPchro3wFZNSNmek8A2kbkOAZLIZAYx1KP/zAqwO0sOHi3xJEb+UBz8NaYt/17UNit1Q9w==

yargs-parser@10.x:
version "10.1.0"
Expand Down

0 comments on commit b410999

Please sign in to comment.