|
| 1 | +import { expect } from 'chai'; |
| 2 | +import { parseResponse } from '../../../remote-queries/run-remote-query'; |
| 3 | + |
| 4 | +describe('run-remote-query', () => { |
| 5 | + describe('parseResponse', () => { |
| 6 | + it('should parse a successful response', () => { |
| 7 | + const result = parseResponse('org', 'name', { |
| 8 | + workflow_run_id: 123, |
| 9 | + repositories_queried: ['a/b', 'c/d'], |
| 10 | + }); |
| 11 | + |
| 12 | + expect(result.popupMessage).to.equal('Successfully scheduled runs. [Click here to see the progress](https://github.com/org/name/actions/runs/123).'); |
| 13 | + expect(result.logMessage).to.equal( |
| 14 | + ['Successfully scheduled runs. See https://github.com/org/name/actions/runs/123.', |
| 15 | + '', |
| 16 | + 'Repositories queried:', |
| 17 | + 'a/b, c/d'].join('\n') |
| 18 | + ); |
| 19 | + }); |
| 20 | + |
| 21 | + it('should parse a response with no repositories queried', () => { |
| 22 | + const result = parseResponse('org', 'name', { |
| 23 | + workflow_run_id: 123, |
| 24 | + }); |
| 25 | + |
| 26 | + expect(result.popupMessage).to.equal('Successfully scheduled runs. [Click here to see the progress](https://github.com/org/name/actions/runs/123).'); |
| 27 | + expect(result.logMessage).to.equal( |
| 28 | + 'Successfully scheduled runs. See https://github.com/org/name/actions/runs/123.' |
| 29 | + ); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should parse a response with invalid repos', () => { |
| 33 | + const result = parseResponse('org', 'name', { |
| 34 | + workflow_run_id: 123, |
| 35 | + repositories_queried: ['a/b', 'c/d'], |
| 36 | + errors: { |
| 37 | + invalid_repositories: ['e/f', 'g/h'], |
| 38 | + } |
| 39 | + }); |
| 40 | + |
| 41 | + expect(result.popupMessage).to.equal( |
| 42 | + ['Successfully scheduled runs. [Click here to see the progress](https://github.com/org/name/actions/runs/123).', |
| 43 | + '', |
| 44 | + 'Some repositories could not be scheduled. See extension log for details.'].join('\n') |
| 45 | + ); |
| 46 | + expect(result.logMessage).to.equal( |
| 47 | + ['Successfully scheduled runs. See https://github.com/org/name/actions/runs/123.', |
| 48 | + '', |
| 49 | + 'Repositories queried:', |
| 50 | + 'a/b, c/d', |
| 51 | + '', |
| 52 | + 'Some repositories could not be scheduled.', |
| 53 | + '', |
| 54 | + 'Invalid repositories:', |
| 55 | + 'e/f, g/h'].join('\n') |
| 56 | + ); |
| 57 | + }); |
| 58 | + |
| 59 | + it('should parse a response with repos w/o databases', () => { |
| 60 | + const result = parseResponse('org', 'name', { |
| 61 | + workflow_run_id: 123, |
| 62 | + repositories_queried: ['a/b', 'c/d'], |
| 63 | + errors: { |
| 64 | + repositories_without_database: ['e/f', 'g/h'], |
| 65 | + } |
| 66 | + }); |
| 67 | + |
| 68 | + expect(result.popupMessage).to.equal( |
| 69 | + ['Successfully scheduled runs. [Click here to see the progress](https://github.com/org/name/actions/runs/123).', |
| 70 | + '', |
| 71 | + 'Some repositories could not be scheduled. See extension log for details.'].join('\n') |
| 72 | + ); |
| 73 | + expect(result.logMessage).to.equal( |
| 74 | + ['Successfully scheduled runs. See https://github.com/org/name/actions/runs/123.', |
| 75 | + '', |
| 76 | + 'Repositories queried:\na/b, c/d', |
| 77 | + '', |
| 78 | + 'Some repositories could not be scheduled.', |
| 79 | + '', |
| 80 | + 'Repositories without databases:\ne/f, g/h'].join('\n') |
| 81 | + ); |
| 82 | + }); |
| 83 | + |
| 84 | + it('should parse a response with invalid repos and repos w/o databases', () => { |
| 85 | + const result = parseResponse('org', 'name', { |
| 86 | + workflow_run_id: 123, |
| 87 | + repositories_queried: ['a/b', 'c/d'], |
| 88 | + errors: { |
| 89 | + invalid_repositories: ['e/f', 'g/h'], |
| 90 | + repositories_without_database: ['i/j', 'k/l'], |
| 91 | + } |
| 92 | + }); |
| 93 | + |
| 94 | + expect(result.popupMessage).to.equal( |
| 95 | + ['Successfully scheduled runs. [Click here to see the progress](https://github.com/org/name/actions/runs/123).', |
| 96 | + '', |
| 97 | + 'Some repositories could not be scheduled. See extension log for details.'].join('\n') |
| 98 | + ); |
| 99 | + expect(result.logMessage).to.equal( |
| 100 | + ['Successfully scheduled runs. See https://github.com/org/name/actions/runs/123.', |
| 101 | + '', |
| 102 | + 'Repositories queried:\na/b, c/d', |
| 103 | + '', |
| 104 | + 'Some repositories could not be scheduled.', |
| 105 | + '', |
| 106 | + 'Invalid repositories:', |
| 107 | + 'e/f, g/h', |
| 108 | + '', |
| 109 | + 'Repositories without databases:', |
| 110 | + 'i/j, k/l'].join('\n') |
| 111 | + ); |
| 112 | + }); |
| 113 | + }); |
| 114 | +}); |
0 commit comments