From 1d160ce2c87739b82027e34355a8a675a9361d0a Mon Sep 17 00:00:00 2001 From: Stephen Collings Date: Thu, 27 Jul 2023 13:39:07 +0100 Subject: [PATCH 1/2] chore: Fix test commands --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5f2c99ea..7777bfc4 100644 --- a/package.json +++ b/package.json @@ -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", From 943a46b504035e7d6598d59ea5b65d4aef3a34f4 Mon Sep 17 00:00:00 2001 From: Stephen Collings Date: Mon, 21 Aug 2023 16:40:57 +0100 Subject: [PATCH 2/2] tests: Failing unit test for autolinks sync No modifications are made if the number of existing and configured autolinks is equal --- test/unit/lib/plugins/autolinks.test.js | 48 +++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 test/unit/lib/plugins/autolinks.test.js diff --git a/test/unit/lib/plugins/autolinks.test.js b/test/unit/lib/plugins/autolinks.test.js new file mode 100644 index 00000000..6656b704 --- /dev/null +++ b/test/unit/lib/plugins/autolinks.test.js @@ -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/' }, + { key_prefix: 'SAME-', url_template: 'https://same/' }, + { key_prefix: 'NEW_URL-', url_template: 'https://new-url/' }, + ]) + + github.repos.listAutolinks.mockResolvedValueOnce({ + data: [ + { id: '1', key_prefix: 'SAME-', url_template: 'https://same/', is_alphanumeric: true }, + { id: '2', key_prefix: 'REMOVE-', url_template: 'https://test/', is_alphanumeric: true }, + { id: '3', key_prefix: 'NEW_URL-', url_template: 'https://old-url/', is_alphanumeric: true }, + ] + }) + + return plugin.sync().then(() => { + expect(github.repos.createAutolink).toHaveBeenCalledWith({ + key_prefix: 'ADD-', + url_template: 'https://add/', + owner: 'bkeepers', + repo: 'test' + }) + }) + }) + }) +})