Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing unit test for Autolinks sync #520

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
"lint:lockfile": "lockfile-lint --path package-lock.json --type npm --validate-https --allowed-hosts npm",
"lint:engines": "check-engine",
"lint:peer": "npm ls >/dev/null",
"test:unit": "jest 'test/unit/'",
"test:unit": "jest --testRegex=test/unit/.*\\.test\\.js",
"test:me": "jest ",
"test:unit:watch": "npm run test:unit -- --watch",
"test:integration": "jest 'test/integration/'",
"test:integration": "jest --testRegex=test/integration/.*\\.test\\.js",
"test:integration:debug": "LOG_LEVEL=debug DEBUG=nock run-s test:integration"
},
"author": "Yadhav Jayaraman",
Expand Down
48 changes: 48 additions & 0 deletions test/unit/lib/plugins/autolinks.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const Autolinks = require('../../../../lib/plugins/autolinks')

describe('Autolinks', () => {
let github

function configure (config) {
const log = { debug: jest.fn(), error: console.error }
const nop = false
return new Autolinks(nop, github, { owner: 'bkeepers', repo: 'test' }, config, log)
}

beforeEach(() => {
github = {
repos: {
listAutolinks: jest.fn().mockResolvedValue([]),
createAutolink: jest.fn().mockResolvedValue(),
deleteAutolink: jest.fn().mockResolvedValue(),
}
}
})

describe('sync', () => {
it('syncs autolinks', () => {
const plugin = configure([
{ key_prefix: 'ADD-', url_template: 'https://add/<num>' },
{ key_prefix: 'SAME-', url_template: 'https://same/<num>' },
{ key_prefix: 'NEW_URL-', url_template: 'https://new-url/<num>' },
])

github.repos.listAutolinks.mockResolvedValueOnce({
data: [
{ id: '1', key_prefix: 'SAME-', url_template: 'https://same/<num>', is_alphanumeric: true },
{ id: '2', key_prefix: 'REMOVE-', url_template: 'https://test/<num>', is_alphanumeric: true },
{ id: '3', key_prefix: 'NEW_URL-', url_template: 'https://old-url/<num>', is_alphanumeric: true },
Comment on lines +32 to +34
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove any line for the test to pass

]
})

return plugin.sync().then(() => {
expect(github.repos.createAutolink).toHaveBeenCalledWith({
key_prefix: 'ADD-',
url_template: 'https://add/<num>',
owner: 'bkeepers',
repo: 'test'
})
})
})
})
})