Skip to content

Instantly share code, notes, and snippets.

@jrichardsz
Last active July 28, 2022 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrichardsz/975632649f94bfda98687243496f8dcf to your computer and use it in GitHub Desktop.
Save jrichardsz/975632649f94bfda98687243496f8dcf to your computer and use it in GitHub Desktop.
mock nodejs snippets

target

function DevopsSettingsService(databaseConnector) {

  this.databaseConnector = databaseConnector;

  console.log(databaseConnector)

  this.createDevopsSettings = async (params) => {

    if (typeof params == "undefined") {
      throw new Error("params is required");
    }
    if (typeof params.repositoryName == "undefined") {
      throw new Error("repositoryName is required");
    }    
    if (typeof params.branchFilter == "undefined") {
      throw new Error("branchFilter is required");
    }    
    if (typeof params.yaml == "undefined") {
      throw new Error("yaml is required");
    }

    let id;

    try {
      id = await this.databaseConnector('devops_settings').insert(params)
    } catch (e) {
      console.log(e);
      throw new Error("Failed while devops settings was being created");
    }
    return id[0];
  }

}

module.exports = DevopsSettingsService;

mock

function databaseConnectorMock() {
  function knexCore(){
    this.insert = () => {
      return [666];
    }	
  }

  return new knexCore();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment