{"size": 2577, "ext": "js", "max_stars_repo_path": "test/unit/message.test.js", "max_stars_repo_name": "DP6/raft-suite-hub", "max_stars_repo_stars_event_min_datetime": "2021-06-30T15:25:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-02T14:06:43.000Z", "max_issues_repo_path": "test/unit/message.test.js", "max_issues_repo_name": "DP6/raft-suite-hub", "max_issues_repo_issues_event_min_datetime": "2021-07-19T03:07:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T03:09:43.000Z", "max_forks_repo_path": "test/unit/message.test.js", "max_forks_repo_name": "DP6/raft-suite-hub", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 6, "max_issues_count": 42, "max_forks_count": null, "avg_line_length": 40.9047619048, "max_line_length": 88, "alphanum_fraction": 0.6713232441}
const { assert, expect } = require('chai');

const { getStatusMessage, hubMessage } = require('../../message');

const REQUIRED_BODY = { module: 'Hub-test', spec: 'Message log', deploy: '1' };

describe('Arquivo de mensagens', () => {
  it('Converte 00-00 em uma mensagem', () => {
    const code = '00-00';
    const message = 'Em análise - Não há ocorrências';
    const statusMessage = getStatusMessage(code);
    expect(statusMessage).to.equal(message);
  });

  it('Converte 01-01 em uma mensagem', () => {
    const code = '01-01';
    const message = 'Disponibilidade - Há um problema na disponibilização do UserID';
    const statusMessage = getStatusMessage(code);
    expect(statusMessage).to.equal(message);
  });

  it('Mensagem gerada tem o schema esperado', () => {
    const message = hubMessage({ ...REQUIRED_BODY });
    expect(message).to.have.property('timestamp');
    expect(message).to.have.property('jobId');
    expect(message).to.have.property('project');
    expect(message).to.have.property('module');
    expect(message).to.have.property('spec');
    expect(message).to.have.property('deploy');
    expect(message).to.have.property('version');
    expect(message).to.have.property('status');
    expect(message).to.have.property('payload');
    expect(message.status).to.have.property('code');
    expect(message.status).to.have.property('message');
    expect(message.status).to.have.property('description');
    expect(message.status).to.have.property('details');
  });

  it('Mensagem gerada tem os tipos esperados', () => {
    const message = hubMessage({ ...REQUIRED_BODY });
    expect(message.timestamp).to.be.a('string');
    expect(message.jobId).to.be.a('string');
    expect(message.project).to.be.a('string');
    expect(message.module).to.be.a('string');
    expect(message.spec).to.be.a('string');
    expect(message.deploy).to.be.a('string');
    expect(message.version).to.be.a('string');
    expect(message.status).to.be.a('object');
    expect(message.status.code).to.be.a('string');
    expect(message.status.message).to.be.a('string');
    expect(message.status.description).to.be.a('string');
    expect(message.status.details).to.be.a('string');
    expect(message.payload).to.be.a('string');
  });

  it('Mensagem gerada tem os parâmetros obrigatórios preenchidos dinamicamente', () => {
    const message = hubMessage({ ...REQUIRED_BODY });
    expect(message.module).to.equal(REQUIRED_BODY.module);
    expect(message.spec).to.equal(REQUIRED_BODY.spec);
    expect(message.deploy).to.equal(REQUIRED_BODY.deploy);
  });
});
