-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add missing nop logic for custom properties plugin
- Loading branch information
Showing
2 changed files
with
169 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,127 +1,142 @@ | ||
const CustomProperties = require('../../../../lib/plugins/custom_properties') | ||
|
||
describe('CustomProperties', () => { | ||
const nop = false | ||
let github | ||
let log | ||
|
||
const owner = 'test-owner' | ||
const repo = 'test-repo' | ||
|
||
function configure (config) { | ||
const nop = false | ||
const errors = [] | ||
return new CustomProperties(nop, github, { owner: 'bkeepers', repo: 'test' }, config, log, errors) | ||
return new CustomProperties(nop, github, { owner, repo }, config, log, []) | ||
} | ||
|
||
beforeEach(() => { | ||
github = { | ||
request: jest.fn() | ||
// .mockResolvedValue({ | ||
// data: [ | ||
// { property_name: 'test', value: 'test' } | ||
// ] | ||
// }) | ||
paginate: jest.fn(), | ||
repos: { | ||
getCustomPropertiesValues: jest.fn(), | ||
createOrUpdateCustomPropertiesValues: jest.fn() | ||
} | ||
} | ||
|
||
log = { debug: jest.fn(), error: console.error } | ||
}) | ||
|
||
describe('sync', () => { | ||
it('syncs custom properties', async () => { | ||
const plugin = configure([ | ||
{ name: 'test', value: 'test' } | ||
]) | ||
describe('Custom Properties plugin', () => { | ||
it('should normalize entries when be instantiated', () => { | ||
const plugin = configure([{ name: 'Test', value: 'test' }]) | ||
expect(plugin.entries).toEqual([{ name: 'test', value: 'test' }]) | ||
}) | ||
|
||
github.request.mockResolvedValue({ | ||
data: [ | ||
{ property_name: 'test', value: 'test' } | ||
] | ||
}) | ||
it('should fetch and normalize custom properties successfully', async () => { | ||
const mockResponse = [ | ||
{ property_name: 'Test1', value: 'value1' }, | ||
{ property_name: 'Test2', value: 'value2' } | ||
] | ||
|
||
return plugin.sync().then(() => { | ||
expect(github.request).toHaveBeenCalledWith('GET /repos/:org/:repo/properties/values', { | ||
org: 'bkeepers', | ||
repo: 'test' | ||
}) | ||
}) | ||
github.paginate.mockResolvedValue(mockResponse) | ||
|
||
const plugin = configure() | ||
const result = await plugin.find() | ||
|
||
expect(github.paginate).toHaveBeenCalledWith( | ||
github.repos.getCustomPropertiesValues, | ||
{ | ||
owner, | ||
repo, | ||
per_page: 100 | ||
} | ||
) | ||
|
||
expect(result).toEqual([ | ||
{ name: 'test1', value: 'value1' }, | ||
{ name: 'test2', value: 'value2' } | ||
]) | ||
}) | ||
}) | ||
describe('sync', () => { | ||
it('add custom properties', async () => { | ||
|
||
it('should sync', async () => { | ||
const mockResponse = [ | ||
{ property_name: 'no-change', value: 'no-change' }, | ||
{ property_name: 'new-value', value: '' }, | ||
{ property_name: 'update-value', value: 'update-value' }, | ||
{ property_name: 'delete-value', value: 'update-value' } | ||
] | ||
|
||
github.paginate.mockResolvedValue(mockResponse) | ||
|
||
const plugin = configure([ | ||
{ name: 'test', value: 'test' } | ||
{ name: 'no-change', value: 'no-change' }, | ||
{ name: 'new-value', value: 'new-value' }, | ||
{ name: 'update-value', value: 'new-value' }, | ||
{ name: 'delete-value', value: null } | ||
]) | ||
|
||
github.request.mockResolvedValue({ | ||
data: [] | ||
}) | ||
|
||
return plugin.sync().then(() => { | ||
expect(github.request).toHaveBeenNthCalledWith(1, 'GET /repos/:org/:repo/properties/values', { | ||
org: 'bkeepers', | ||
repo: 'test' | ||
}) | ||
expect(github.request).toHaveBeenNthCalledWith(2, 'PATCH /repos/:org/:repo/properties/values', { | ||
org: 'bkeepers', | ||
repo: 'test', | ||
expect(github.paginate).toHaveBeenCalledWith( | ||
github.repos.getCustomPropertiesValues, | ||
{ | ||
owner, | ||
repo, | ||
per_page: 100 | ||
} | ||
) | ||
expect(github.repos.createOrUpdateCustomPropertiesValues).not.toHaveBeenCalledWith({ | ||
owner, | ||
repo, | ||
properties: [ | ||
{ | ||
property_name: 'test', | ||
value: 'test' | ||
property_name: 'no-change', | ||
value: 'no-change' | ||
} | ||
] | ||
}) | ||
}) | ||
}) | ||
}) | ||
describe('sync', () => { | ||
it('remove custom properties', async () => { | ||
const plugin = configure([]) | ||
|
||
github.request.mockResolvedValue({ | ||
data: [{ property_name: 'test', value: 'test' }] | ||
}) | ||
|
||
return plugin.sync().then(() => { | ||
expect(github.request).toHaveBeenNthCalledWith(1, 'GET /repos/:org/:repo/properties/values', { | ||
org: 'bkeepers', | ||
repo: 'test' | ||
}) | ||
expect(github.request).toHaveBeenNthCalledWith(2, 'PATCH /repos/:org/:repo/properties/values', { | ||
org: 'bkeepers', | ||
repo: 'test', | ||
expect(github.repos.createOrUpdateCustomPropertiesValues).toHaveBeenCalledWith({ | ||
owner, | ||
repo, | ||
properties: [ | ||
{ | ||
property_name: 'test', | ||
value: null | ||
property_name: 'new-value', | ||
value: 'new-value' | ||
} | ||
] | ||
}) | ||
}) | ||
}) | ||
}) | ||
describe('sync', () => { | ||
it('update custom properties', async () => { | ||
const plugin = configure([ | ||
{ name: 'test', value: 'foobar' } | ||
]) | ||
|
||
github.request.mockResolvedValue({ | ||
data: [{ property_name: 'test', value: 'test' }] | ||
}) | ||
|
||
return plugin.sync().then(() => { | ||
expect(github.request).toHaveBeenNthCalledWith(1, 'GET /repos/:org/:repo/properties/values', { | ||
org: 'bkeepers', | ||
repo: 'test' | ||
expect(github.repos.createOrUpdateCustomPropertiesValues).toHaveBeenCalledWith({ | ||
owner, | ||
repo, | ||
properties: [ | ||
{ | ||
property_name: 'update-value', | ||
value: 'new-value' | ||
} | ||
] | ||
}) | ||
expect(github.request).toHaveBeenNthCalledWith(2, 'PATCH /repos/:org/:repo/properties/values', { | ||
org: 'bkeepers', | ||
repo: 'test', | ||
expect(github.repos.createOrUpdateCustomPropertiesValues).toHaveBeenCalledWith({ | ||
owner, | ||
repo, | ||
properties: [ | ||
{ | ||
property_name: 'test', | ||
value: 'foobar' | ||
property_name: 'delete-value', | ||
value: null | ||
} | ||
] | ||
}) | ||
}) | ||
|
||
// const plugin = configure([{ name: 'Test', value: 'test' }]) | ||
// await plugin.update({ name: 'test', value: 'old' }, { name: 'test', value: 'test' }) | ||
|
||
// expect(github.repos.createOrUpdateCustomPropertiesValues).toHaveBeenCalledWith({ | ||
// owner, | ||
// repo, | ||
// properties: [ | ||
// { | ||
// property_name: 'test', | ||
// value: 'test' | ||
// } | ||
// ] | ||
// }) | ||
}) | ||
}) | ||
}) |