<commit_before>var assert = require('assert');
debugger;

describe('Workflow Core', function() {
  this.timeout(5000);
  
  after(function() {
    apos.db.dropDatabase();
  });

  it('should be a property of the apos object', function(done) {
    apos = require('apostrophe')({
      testModule: true,

      modules: {
        'apostrophe-pages': {
          park: [],
          types: [
            {
              name: 'home',
              label: 'Home'
            },
            {
              name: 'testPage',
              label: 'Test Page'
            }
          ]
        },
        'apostrophe-workflow': {
          settings: {
            locales: ['default'],
            defaultLocale: 'default',
          },
          alias: 'workflow' // for testing only!
        },
        'products': {
          extend: 'apostrophe-pieces',
          name: 'product',
          alias: 'products'
        }
      },
      afterInit: function(callback) {
        assert(apos.modules['apostrophe-workflow']);
        return callback(null);
      },
      afterListen: function(err) {
        if (err) {
          console.log("Existrs", err);
        }

        assert(!err);
        done();
      }
    });
  });

  it('Test add draft product to db as draft', () => {
    const req = apos.tasks.getReq();
    return apos.products.insert(req, {
      title: 'initial title',
      published: true
    })
      .then(doc => {
        console.log("DOC", doc)
        assert(doc.type === 'product');
        assert(doc.workflowGuid);
        assert(doc.workflowLocale === 'default-draft');
      });
  });
  
  it('Export our product to default (live)', () => {
    console.log('test commit')
    var req = apos.tasks.getReq({locale: 'default-draft'});
    // load it from db again 
    apos.products.find(req).toArray().then( docs => {
      assert(docs[0]);
      apos.workflow.commitLatest(req, docs[0]._id, (err, res) => {
          console.log("EXPORT", res);
          if (err) {
            console.log(err);
          }
          assert(!err);
          assert(commitId);
          assert(draftTitle === 'initial title');
          console.log('first');
          done();
      });
    });
  });

  it('Check for live document after commit', done => {
    console.log('second');
    const req = apos.tasks.getReq({locale: 'default'});
    apos.products.find(req).toArray().then( docs => {
       console.log("FOUND", docs);
       done();
    });
  });
});
<commit_msg>tests<commit_after>var assert = require('assert');
var async = require('async');
debugger;

describe('Workflow Core', function() {
  this.timeout(5000);
  
  after(function() {
    /* apos.db.dropDatabase(); */
  });

  it('should be a property of the apos object', function(done) {
    apos = require('apostrophe')({
      testModule: true,

      modules: {
        'apostrophe-pages': {
          park: [],
          types: [
            {
              name: 'home',
              label: 'Home'
            },
            {
              name: 'testPage',
              label: 'Test Page'
            }
          ]
        },
        'apostrophe-workflow': {
          settings: {
            locales: ['default'],
            defaultLocale: 'default',
          },
          alias: 'workflow' // for testing only!
        },
        'products': {
          extend: 'apostrophe-pieces',
          name: 'product',
          alias: 'products'
        }
      },
      afterInit: function(callback) {
        assert(apos.modules['apostrophe-workflow']);
        return callback(null);
      },
      afterListen: function(err) {
        if (err) {
          console.log("Existrs", err);
        }

        assert(!err);
        done();
      }
    });
  });

  it('Test add draft product to db as draft', () => {
    const req = apos.tasks.getReq();
    return apos.products.insert(req, {
      title: 'initial title',
      published: true
    })
      .then(doc => {
        console.log("DOC", doc)
        assert(doc.type === 'product');
        assert(doc.workflowGuid);
        assert(doc.workflowLocale === 'default-draft');
      });
  });
  
  it('Commmit a change', (done) => {
    var req = apos.tasks.getReq({locale: 'default-draft'});

    async.waterfall([getProductDraft, updateProductDraft, commitUpdate], (err, res) => {
      assert(!err);
      assert(typeof res === 'string', 'response should be an id');
      done();
    })
    
    function getProductDraft(cb) {
      apos.products.find(req).toArray().then( docs => {
        assert(docs[0]);
        return cb(null, docs[0]);
      })
      .catch(e => {
        return cb(e)
      });
    }

    function updateProductDraft(product, cb) {
      product.title = 'new title';
      apos.products.update(req, product, (err, res) => {
        return cb(err, res);
      });
    }

    function commitUpdate(product, cb) {
      apos.workflow.commitLatest(req, product._id, (err, res) => {
        console.log('workflow commit success',err, res);
        return cb(err, res);
      });
    }
  });

  it('Check for live document after commit', done => {
    const req = apos.tasks.getReq({locale: 'default'});
    apos.products.find(req).toArray().then( docs => {
       console.log("FOUND", docs);
       assert(docs[0].title === 'new title');
       assert(!docs[0].trash)
       done();
    });
  });
});
{'fraction_non_alphanumeric': 0.16495614853517448, 'fraction_numerical': 0.0026124276917335325, 'mean_word_length': 1.834479111581174, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '5582940', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1604, 'n_words': 323}