<commit_before>const { Bagger } = require('./bagger');
const { BagItProfile } = require('./bagit_profile');
const fs = require('fs');
const { Job } = require('../core/job');
const os = require('os');
const { PackagingOperation } = require('../core/packaging_operation');
const path = require('path');

var tmpFile = path.join(os.tmpdir(), 'TestBag.tar');

afterEach(() => {
    if (fs.existsSync(tmpFile)) {
        fs.unlinkSync(tmpFile);
    }
});


// TODO:
//
// 1. Don't use filter and find in BagItProfile to find tags
// because that returns copies instead of references.
//
// findMatchingTags
// findMatchingTag
// getTagsFromFile
//
// 2. Make sure tags are written correctly to tag files.
//
// 3. Validate entire bag.
//
// 4. Check for expected payload files.
//

function getJob() {
    var job = new Job();
    job.packagingOperation = new PackagingOperation('TestBag', tmpFile, '.tar');
    var sourceDir = path.join(__dirname, '..', 'util');
    job.packagingOperation.sourceFiles.push(sourceDir);
    var profilesDir = path.join(__dirname, '..', 'test', 'profiles');
    job.bagItProfile = BagItProfile.load(path.join(profilesDir, 'multi_manifest.json'));

    // Set required APTrust tags
    var access = job.bagItProfile.firstMatchingTag('Access');
    access.userValue = 'Institution';
    var title = job.bagItProfile.firstMatchingTag('Title');
    title.userValue = 'Test Bag';
    var description = job.bagItProfile.firstMatchingTag('Description');
    description.userValue = 'Bag of files for unit testing.';
    return job;
}

test('create()', done => {
    let bagger = new Bagger(getJob());
    bagger.on('finish', function() {
        let result = bagger.job.packagingOperation.result;
        //console.log(result);
        expect(result.error).toBeNull();
        expect(result.succeeded).toEqual(true);
        expect(result.started).not.toBeNull();
        expect(result.competed).not.toBeNull();
        expect(result.operation).toEqual('bagging');
        expect(result.provider).toEqual('DART bagger');<commit_msg>Because there's always more to do<commit_after>const { Bagger } = require('./bagger');
const { BagItProfile } = require('./bagit_profile');
const fs = require('fs');
const { Job } = require('../core/job');
const os = require('os');
const { PackagingOperation } = require('../core/packaging_operation');
const path = require('path');

var tmpFile = path.join(os.tmpdir(), 'TestBag.tar');

afterEach(() => {
    if (fs.existsSync(tmpFile)) {
        fs.unlinkSync(tmpFile);
    }
});


// TODO:
//
// 1. Don't use filter and find in BagItProfile to find tags
// because that returns copies instead of references.
//
// findMatchingTags
// findMatchingTag
// getTagsFromFile
//
// 2. Make sure tags are written correctly to tag files.
//
// 3. Set internal tags, like Payload-Oxum, Bagging-Date,
// Bagging-Software, etc.
//
// 4. Validate entire bag.
//
// 5. Check for expected payload files.
//

function getJob() {
    var job = new Job();
    job.packagingOperation = new PackagingOperation('TestBag', tmpFile, '.tar');
    var sourceDir = path.join(__dirname, '..', 'util');
    job.packagingOperation.sourceFiles.push(sourceDir);
    var profilesDir = path.join(__dirname, '..', 'test', 'profiles');
    job.bagItProfile = BagItProfile.load(path.join(profilesDir, 'multi_manifest.json'));

    // Set required APTrust tags
    var access = job.bagItProfile.firstMatchingTag('Access');
    access.userValue = 'Institution';
    var title = job.bagItProfile.firstMatchingTag('Title');
    title.userValue = 'Test Bag';
    var description = job.bagItProfile.firstMatchingTag('Description');
    description.userValue = 'Bag of files for unit testing.';
    return job;
}

test('create()', done => {
    let bagger = new Bagger(getJob());
    bagger.on('finish', function() {
        let result = bagger.job.packagingOperation.result;
        //console.log(result);
        expect(result.error).toBeNull();
        expect(result.succeeded).toEqual(true);
        expect(result.started).not.toBeNull();
        expect(result.competed).not.toBeNull();
        expect(result.operation).toEqual('bagging');
        expect(result.provider).toEqual('DART bagger');
{'fraction_non_alphanumeric': 0.16053194015673236, 'fraction_numerical': 0.0021372595582996915, 'mean_word_length': 3.524167561761547, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4398798', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1261, 'n_words': 295}