import sinon from 'sinon';
import chai from 'chai';
const expect = chai.expect;
import * as fetch from '../../../src/functions/fetch.js';
import checkGenerator from '../../../src/wordpress/generator';

describe('wordpress', function() {
  describe('test generator promise', function() {
    let sandbox;

    beforeEach(function() {
      sandbox = sinon.sandbox.create();
    });

    afterEach(function() {
      sandbox.restore();
    });

    it('should return original URL even if generator is filled', () => {
      const html = [
        {
          type: 'tag',
          name: 'html',
          children: [
            {
              type: 'tag',
              name: 'head',
              children: [
                {
                  type: 'tag',
                  name: 'title',
                },
                {
                  type: 'tag',
                  name: 'meta',
                  attribs: {
                      name: 'generator',
                      content: 'WordPress X.Y.Z',
                  },
                },
              ],
            },
            {
              type: 'tag',
              name: 'body',
              children: [],
            },
          ],
        },
      ];

      sandbox.stub(fetch, 'fetch').returns(html);

      return new Promise((resolve, reject) => {
        resolve('https://www.juffalow.com');
        })
        .then(checkGenerator)
        .then((r) => {
          expect(r).to.equal('https://www.juffalow.com');
        });
    });
  });
});

import sinon from 'sinon';
import chai from 'chai';
const expect = chai.expect;
import * as fetch from '../../../src/functions/fetch.js';
import checkGenerator from '../../../src/wordpress/generator';

describe('wordpress', function() {
  describe('test generator promise', function() {
    let sandbox;

    beforeEach(function() {
      sandbox = sinon.sandbox.create();
    });

    afterEach(function() {
      sandbox.restore();
    });

    it('should return array of results, with one result, that contains errors', () => {
      const html = {
        body: '<html><head><meta name="generator" content="WordPress X.Y.Z" /></head><body><p>Text</p></body></html>',
      };

      sandbox.stub(fetch, 'fetch').returns(html);

      return checkGenerator('https://juffalow.com/')
        .then((r) => {
          expect(r.messages.length).to.equal(0);
          expect(r.errors.length).to.equal(2);
        });
    });
  });
});

Fix generator promise test