|
| 1 | +/*global describe, it*/ |
| 2 | +import mockedFunctions from "../setupMocks.js"; |
| 3 | +import * as chai from 'chai'; |
| 4 | +import {getGithubReleaseStatus, getGetGithubReleaseStatusSchema} from "../../../src/api/getGithubReleaseStatus.js"; |
| 5 | +import {getSimpleGetReply, getSimpleGETRequest} from '../data/simple-request.js'; |
| 6 | +import Ajv from "ajv"; |
| 7 | +import db from "../../../src/db.js"; |
| 8 | + |
| 9 | +export const AJV = new Ajv(); |
| 10 | + |
| 11 | + |
| 12 | +let expect = chai.expect; |
| 13 | + |
| 14 | +describe('unit Tests for getGithubReleaseStatus api', function () { |
| 15 | + function _getRequest(owner="owner", repo ="repo", tag= "tag") { |
| 16 | + let request = getSimpleGETRequest(); |
| 17 | + request.query.owner = owner; |
| 18 | + request.query.repo = repo; |
| 19 | + request.query.tag = tag; |
| 20 | + return request; |
| 21 | + } |
| 22 | + |
| 23 | + it('should getGithubReleaseStatus return no such release if no release', async function () { |
| 24 | + let helloResponse = await getGithubReleaseStatus(_getRequest(), getSimpleGetReply()); |
| 25 | + expect(helloResponse).eql({ |
| 26 | + "errors": [ |
| 27 | + "Release not found. IF this is a recent release, please wait for 1 minute before checking again." |
| 28 | + ], |
| 29 | + "status": "NO_SUCH_RELEASE" |
| 30 | + }); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should getGithubReleaseStatus return existing release details', async function () { |
| 34 | + db.getFromIndex = function (_tableName) { |
| 35 | + return { |
| 36 | + isSuccess: true, |
| 37 | + documents: [{ |
| 38 | + published: false, |
| 39 | + status: "PROCESSING", |
| 40 | + errors: ["oops"], |
| 41 | + githubIssue: "5", |
| 42 | + lastUpdatedDateUTC: 1234 |
| 43 | + }]}; |
| 44 | + }; |
| 45 | + let helloResponse = await getGithubReleaseStatus(_getRequest(), getSimpleGetReply()); |
| 46 | + expect(helloResponse).eql({ |
| 47 | + "errors": [ |
| 48 | + "oops" |
| 49 | + ], |
| 50 | + "githubIssue": "5", |
| 51 | + "lastUpdatedDateUTC": 1234, |
| 52 | + "published": false, |
| 53 | + "status": "PROCESSING" |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should validate schemas for sample request/responses', async function () { |
| 58 | + let request = _getRequest(); |
| 59 | + // request |
| 60 | + const requestValidator = AJV.compile(getGetGithubReleaseStatusSchema().schema.querystring); |
| 61 | + expect(requestValidator(request.query)).to.be.true; |
| 62 | + // response |
| 63 | + const successResponseValidator = AJV.compile(getGetGithubReleaseStatusSchema().schema.response["200"]); |
| 64 | + let response = await getGithubReleaseStatus(_getRequest(), getSimpleGetReply()); |
| 65 | + expect(successResponseValidator(response)).to.be.true; |
| 66 | + }); |
| 67 | + |
| 68 | + it('should throw if db non success getGithubReleaseStatus', async function () { |
| 69 | + db.getFromIndex = function (_tableName) { |
| 70 | + return {isSuccess: false}; |
| 71 | + }; |
| 72 | + let error; |
| 73 | + try{ |
| 74 | + await getGithubReleaseStatus(_getRequest(), getSimpleGetReply()); |
| 75 | + } catch(e){ |
| 76 | + error = e; |
| 77 | + } |
| 78 | + expect(error).to.exist; |
| 79 | + }); |
| 80 | +}); |
0 commit comments