<commit_before>import nock from 'nock';

import { SMSAPI } from '../../smsapi';

const { SMSAPI_OAUTH_TOKEN, SMSAPI_API_URL } = process.env;

const smsapi = new SMSAPI(SMSAPI_OAUTH_TOKEN || '', SMSAPI_API_URL || '');

describe('Base message module', () => {
  afterEach(() => {
    nock.cleanAll();
  });

  it('should trim message', async () => {
    // given
    const number = '500000000';
    const message = 'someMessage';

    const req = nock(`${SMSAPI_API_URL}`)
      .post('/sms.do', {
        details: true,
        encoding: 'utf-8',
        format: 'json',
        message,
        to: number,
      })
      .reply(200);

    // when
    try {
      await smsapi.sms.sendSms(number, `  ${message} `);
    } catch {} // eslint-disable-line

    // then
    expect(req.isDone()).toBeTruthy();
  });

  it('should parseFloat points if returned as string', async () => {
    // given
    const number = '500000000';
    const message = 'someMessage';

    const points = '0.1';

    const req = nock(`${SMSAPI_API_URL}`)
      .post('/sms.do', {
        details: true,
        encoding: 'utf-8',
        format: 'json',
        message,
        to: number,
      })
      .reply(200, {
        count: 1,
        list: [
          {
            date_sent: new Date(),
            points,
          },
        ],
      });

    // when
    const res = await smsapi.sms.sendSms(number, message);

    // then
    expect(req.isDone()).toBeTruthy();
    expect(res.list[0].points).toEqual(0.1);
  });

  it('should add dateValidate when date is present', async () => {
    // given
    const number = '500000000';
    const message = 'someMessage';

    const date = new Date();

    const req = nock(`${SMSAPI_API_URL}`)
      .post('/sms.do', {
        date: date.toISOString(),
        date_validate: true,
        details: true,
        encoding: 'utf-8',
        format: 'json',
        message,
        to: number,
      })
      .reply(200);

    // when
    try {<commit_msg>baseMessageModule test refactor<commit_after>import nock from 'nock';

import { SMSAPI } from '../../smsapi';

const smsapi = new SMSAPI('someToken');

describe('Base message module', () => {
  afterEach(() => {
    nock.cleanAll();
  });

  it('should trim message', async () => {
    // given
    const number = '500000000';
    const message = 'someMessage';

    const req = nock('https://smsapi.io/api')
      .post('/sms.do', {
        details: true,
        encoding: 'utf-8',
        format: 'json',
        message,
        to: number,
      })
      .reply(200);

    // when
    try {
      await smsapi.sms.sendSms(number, `  ${message} `);
    } catch {} // eslint-disable-line

    // then
    expect(req.isDone()).toBeTruthy();
  });

  it('should parseFloat points if returned as string', async () => {
    // given
    const number = '500000000';
    const message = 'someMessage';

    const points = '0.1';

    const req = nock('https://smsapi.io/api')
      .post('/sms.do', {
        details: true,
        encoding: 'utf-8',
        format: 'json',
        message,
        to: number,
      })
      .reply(200, {
        count: 1,
        list: [
          {
            date_sent: new Date(),
            points,
          },
        ],
      });

    // when
    const res = await smsapi.sms.sendSms(number, message);

    // then
    expect(req.isDone()).toBeTruthy();
    expect(res.list[0].points).toEqual(0.1);
  });

  it('should add dateValidate when date is present', async () => {
    // given
    const number = '500000000';
    const message = 'someMessage';

    const date = new Date();

    const req = nock('https://smsapi.io/api')
      .post('/sms.do', {
        date: date.toISOString(),
        date_validate: true,
        details: true,
        encoding: 'utf-8',
        format: 'json',
        message,
        to: number,
      })
      .reply(200);

    // when
    try {
{'fraction_non_alphanumeric': 0.1659846547314578, 'fraction_numerical': 0.023017902813299233, 'mean_word_length': 1.8948926720947445, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 6, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1074098', 'n_tokens_mistral': 1349, 'n_tokens_neox': 1267, 'n_words': 283}