var assert = require('chai').assert;
var PgBoss = require('../src/index');
var helper = require('./testHelper');

describe('examples', function(){

    var _boss;
    
    after(function(finished){
        _boss.stop().then(() => finished());
    });

    it('readme example is totes valid', function(finished){
        var connectionString = helper.connectionString;
        
        // example start
        var boss = new PgBoss(connectionString);

        _boss = boss; // exclude test code

        boss.start()
            .then(ready)
            .catch(error => console.error(error));
        
        function ready() {
            boss.publish('work', {message: 'stuff'})
                .then(jobId => console.log(`sent job ${jobId}`));

            boss.subscribe('work', (job, done) => {
                console.log(`got job ${job.name} (${job.id}) ${JSON.stringify(job.data)}`);

                done().then(() => {
                    console.log('Confirmed done');
                    assert.equal('work', job.name); // exclude test code
                    assert.equal('stuff', job.data.message); // exclude test code
                    finished();   // exclude test code
                });
            });
        }
        // example end
    });
});

@@ -827,11 +827,16 @@
 og(%60
-got
+received
  job
@@ -859,19 +859,48 @@
 job.id%7D)
- $%7B
+%60);%0A                console.log(
 JSON.str
@@ -915,18 +915,16 @@
 ob.data)
-%7D%60
 );%0A%0A    

update example test