<commit_before>"use strict"

const should = require('should')
const rewire = require('rewire')

const utils = rewire('../adr_util_sync.js')


describe("Synchronous ADR Utils", () => {
    describe("contentOf", () => {
        it ("should throw an exception when an invalid ADR ID is given",() => {
            should.throws(() => {
                utils.createUtilContext().contentOf("-1")
            }, /could not find ADR file for ADR/i,"should throw a not found exception")
        })

        it("should throw an exception if no ADR directory is found",() => {
            let revert = utils.__set__({
                walker : (start,opts) => []
            })

            should.throws(() => {
                utils.createUtilContext().contentOf("1")
            },/no adr directory found/i,"should fail with 'no adr directory found'")

            revert()
        })

        it("should find the file with the correct ADR id, and return whatever is read from it", () => {
            let expectedFilename = "1-blabla.md"
            let expectedFileContent = "some string"
            let revert = utils.__set__({
                resolveADRDir : (start) => "."
                , allADRFiles : () => ["2-test.md",expectedFilename,"1 wrong.md","1_stillwrong.md"]
                , fs : {
                    readFileSync : (filename) => {
                        filename.should.equal(expectedFilename)
                        return expectedFileContent
                    }
                }
            })

            utils.createUtilContext().contentOf("1").should.equal(expectedFileContent)

            revert()
        })
    })

    describe("linksFor",() => {

        const mockData = adrContent => {
            return {
                resolveADRDir : (start) => "."
                , allADRFiles : () => ["1-test.md"]
                , fs : {
                    readFileSync : filename => adrContent
                }
            }
        }

        it("should throw an exception when an invalid ADR id is given",() => {
            

            should.throws(() => {
                utils.createUtilContext().linksFor("-1")
            }, /could not find ADR file for ADR/i,"should throw a not found exception")
        })

        it("should find links in the status section, with no markdown link",() => {<commit_msg>cleanup: removing duplication in tests<commit_after>"use strict"

const should = require('should')
const rewire = require('rewire')

const utils = rewire('../adr_util_sync.js')

const testInvalidIDThrowsException = block => {
    should.throws(block, /could not find ADR file for ADR/i,"should throw a 'not found exception'")
}

describe("Synchronous ADR Utils", () => {
    describe("contentOf", () => {
        it ("should throw an exception when an invalid ADR ID is given",() => {
            testInvalidIDThrowsException(() => utils.createUtilContext().contentOf("-1"))
        })

        it("should throw an exception if no ADR directory is found",() => {
            let revert = utils.__set__({
                walker : (start,opts) => []
            })

            should.throws(() => {
                utils.createUtilContext().contentOf("1")
            },/no adr directory found/i,"should fail with 'no adr directory found'")

            revert()
        })

        it("should find the file with the correct ADR id, and return whatever is read from it", () => {
            let expectedFilename = "1-blabla.md"
            let expectedFileContent = "some string"
            let revert = utils.__set__({
                resolveADRDir : (start) => "."
                , allADRFiles : () => ["2-test.md",expectedFilename,"1 wrong.md","1_stillwrong.md"]
                , fs : {
                    readFileSync : (filename) => {
                        filename.should.equal(expectedFilename)
                        return expectedFileContent
                    }
                }
            })

            utils.createUtilContext().contentOf("1").should.equal(expectedFileContent)

            revert()
        })
    })

    describe("linksFor",() => {

        const mockData = adrContent => {
            return {
                resolveADRDir : (start) => "."
                , allADRFiles : () => ["1-test.md"]
                , fs : {
                    readFileSync : filename => adrContent
                }
            }
        }

        it("should throw an exception when an invalid ADR id is given",() => {
            testInvalidIDThrowsException(() => utils.createUtilContext().linksFor("-1"))
        })

        it("should find links in the status section, with no markdown link",() => {
{'fraction_non_alphanumeric': 0.12957806810880274, 'fraction_numerical': 0.003855215249518098, 'mean_word_length': 1.6869965477560414, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 42, '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': '2858346', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1182, 'n_words': 310}