From 6229e2b46f9eb5b2c2bfdac76fe7bcd40a4a4308 Mon Sep 17 00:00:00 2001 From: ssube Date: Sat, 15 Aug 2020 16:10:03 -0500 Subject: [PATCH] fix(test): cover label color selection and update --- scripts/mocha-preload.js | 9 ++++++- test/sync/TestSyncLabels.ts | 49 +++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/scripts/mocha-preload.js b/scripts/mocha-preload.js index a65a5c5..7e1bdb2 100644 --- a/scripts/mocha-preload.js +++ b/scripts/mocha-preload.js @@ -1,10 +1,17 @@ export const jsdom = require('jsdom-global')(); -const sourceMapSupport = require('source-map-support'); +const sourceMapSupport = require('source-map-support'); sourceMapSupport.install({ environment: 'node', handleUncaughtExceptions: true, hookRequire: true, }); +const chai = require('chai'); +const chaiPromise = require('chai-as-promised'); +const chaiSinon = require('sinon-chai'); + +chai.use(chaiPromise); +chai.use(chaiSinon); + window.URL.createObjectURL = function () { }; diff --git a/test/sync/TestSyncLabels.ts b/test/sync/TestSyncLabels.ts index 12ff906..6a8b9b2 100644 --- a/test/sync/TestSyncLabels.ts +++ b/test/sync/TestSyncLabels.ts @@ -1,5 +1,54 @@ import { expect } from 'chai'; +import { alea } from 'seedrandom'; +import { match, spy } from 'sinon'; + +import { BunyanLogger } from '../../src/logger/bunyan'; +import { GithubRemote } from '../../src/remote/github'; +import { syncSingleLabel } from '../../src/sync'; describe('label sync', () => { it('should sync each label'); + it('should pick a stable random color for each label', async () => { + const logger = BunyanLogger.create({ + name: 'test', + }); + const remote = new GithubRemote({ + data: {}, + dryrun: true, + logger, + type: '', + }); + const updateSpy = spy(remote, 'updateLabel'); + + await syncSingleLabel({ + colors: [ + 'ff0000', + ], + flags: [{ + adds: [], + name: 'foo', + priority: 1, + removes: [], + requires: [], + }], + logger, + project: '', + random: alea(), + remote, + states: [], + }, { + color: '', + desc: '', + name: 'foo', + project: '', + }); + + expect(updateSpy).to.have.callCount(1); + + const COLOR_LENGTH = 6; + expect(updateSpy).to.have.been.calledWithMatch({ + color: match.string.and(match((it) => it.length === COLOR_LENGTH)), + name: 'foo', + }); + }); });