<commit_before>require "lang.Signal"
require "specs.Cocos2d-x"
require "Logger"
require "Common"

Log.setLevel(LogLevel.Info)

require "royal.AdConfig"
require "royal.AdPresentationQueue"
require "royal.AdTier"
require "royal.AdUnit"
require "royal.AdManifest"

AdConfig.singleton.setBasePath("/path/")

describe("AdPresentationQueue", function()
    local subject = false

    local evolutions

    local adUnit1
    local adUnit2
    local adUnit3
    local tier1
    local tier2
    local tier3
    local tier4
    local tier5

    local fn__callback
    local wasCalled
    local tier
    
    before_each(function()
        -- Prevent AdTier from loading clicks from disk.
        stub(io, "open")
        stub(io, "input")
        stub(io, "output")
        stub(io, "read")
        stub(io, "write")
        stub(io, "close")

        evolutions = {}

        wasCalled = false
        tier = false
        fn__callback = function(t)
            wasCalled = true
            tier = t
        end

        local function fn__shouldShowTier(config)
            if not config then
                return false
            end
            for _, v in ipairs(evolutions) do
                if v == config.evolution then
                    return true
                end
            end
            return false
        end

        tier1 = AdTier(1000, "http://www.example.com/tier/1000", 20, "Click 1", 86400, 1, {evolution = 3})
        tier2 = AdTier(1001, "http://www.example.com/tier/1001", 50, "Click 2", 86400, 2, {evolution = 6})
        tier3 = AdTier(1002, "http://www.example.com/tier/1002", 70, "Click 3", 86400, 1, {evolution = 9})
        adUnit1 = AdUnit(100, 86400, 86500, 4, 86400, {tier1, tier2, tier3})

        tier4 = AdTier(2000, "http://www.example.com/tier/2000", 100, "Click 4", 86400, 1)
        stub(tier4, "isActive", true)
        adUnit2 = AdUnit(200, 85000, 87000, 1, 86400, {tier4})
        stub(adUnit2, "isActive", true)

        tier5 = AdTier(3000, "http://www.example.com/tier/3000", 100, "Click 5", 86400, 1)
        stub(tier5, "isActive", true)
        adUnit3 = AdUnit(300, 85000, 87000, 1, 86400, {tier5})
        stub(adUnit3, "isActive", true)

        local manifest = AdManifest()
        manifest.setAdUnits({adUnit1, adUnit2, adUnit3})
        subject = AdPresentationQueue(manifest, fn__shouldShowTier)
    end)

    describe("getNextTiers", function()
        before_each(function()
            spy.on(cu, "SpriteButton")

            evolutions = {3, 6, 9}
        end)

        describe("when the first button's tier is inactive", function()
            before_each(function()
                stub(adUnit1, "isActive", true)
                stub(tier1, "isActive", false)
                stub(tier2, "isActive", true)<commit_msg>Updated specs to reflect changes to AdVendor class<commit_after>require "lang.Signal"
require "specs.Cocos2d-x"
require "Logger"
require "Common"

Log.setLevel(LogLevel.Info)

require "royal.AdConfig"
require "royal.AdVendor"
require "royal.AdTier"
require "royal.AdUnit"
require "royal.AdManifest"

AdConfig.singleton.setBasePath("/path/")

describe("AdVendor", function()
    local subject = false

    local evolutions

    local adUnit1
    local adUnit2
    local adUnit3
    local tier1
    local tier2
    local tier3
    local tier4
    local tier5

    local fn__callback
    local wasCalled
    local tier
    
    before_each(function()
        -- Prevent AdTier from loading clicks from disk.
        stub(io, "open")
        stub(io, "input")
        stub(io, "output")
        stub(io, "read")
        stub(io, "write")
        stub(io, "close")

        evolutions = {}

        wasCalled = false
        tier = false
        fn__callback = function(t)
            wasCalled = true
            tier = t
        end

        local function fn__shouldShowTier(config)
            if not config then
                return false
            end
            for _, v in ipairs(evolutions) do
                if v == config.evolution then
                    return true
                end
            end
            return false
        end

        tier1 = AdTier(1000, "http://www.example.com/tier/1000", 20, "Click 1", 86400, 1, {evolution = 3})
        tier2 = AdTier(1001, "http://www.example.com/tier/1001", 50, "Click 2", 86400, 2, {evolution = 6})
        tier3 = AdTier(1002, "http://www.example.com/tier/1002", 70, "Click 3", 86400, 1, {evolution = 9})
        adUnit1 = AdUnit(100, 86400, 86500, 4, 86400, {tier1, tier2, tier3})

        tier4 = AdTier(2000, "http://www.example.com/tier/2000", 100, "Click 4", 86400, 1)
        stub(tier4, "isActive", true)
        adUnit2 = AdUnit(200, 85000, 87000, 1, 86400, {tier4})
        stub(adUnit2, "isActive", true)

        tier5 = AdTier(3000, "http://www.example.com/tier/3000", 100, "Click 5", 86400, 1)
        stub(tier5, "isActive", true)
        adUnit3 = AdUnit(300, 85000, 87000, 1, 86400, {tier5})
        stub(adUnit3, "isActive", true)

        local manifest = AdManifest()
        manifest.setAdUnits({adUnit1, adUnit2, adUnit3})
        subject = AdVendor(manifest, fn__shouldShowTier)
    end)

    describe("getNextTiers", function()
        before_each(function()
            spy.on(cu, "SpriteButton")

            evolutions = {3, 6, 9}
        end)

        describe("when the first button's tier is inactive", function()
            before_each(function()
                stub(adUnit1, "isActive", true)
                stub(tier1, "isActive", false)
                stub(tier2, "isActive", true)
{'fraction_non_alphanumeric': 0.1180480803731611, 'fraction_numerical': 0.06530319339791892, 'mean_word_length': 2.1604308390022675, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 10, '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': '7284875', 'n_tokens_mistral': 2066, 'n_tokens_neox': 1797, 'n_words': 458}