Module:WADP Backend/TestCases
Appearance
This module is rated as pre-alpha. It is unfinished, and may or may not be in active development. It should not be used from article namespace pages. Modules remain pre-alpha until the original editor (or someone who takes one over if it is abandoned for some time) is satisfied with the basic structure. |
Unit tests for the Wikimedia Affiliates Data Portal backend system.
Usage
[edit]All tests passed.
Name | Expected | Actual | |
---|---|---|---|
testCountAffiliatesInFinalNotice | |||
testCountAffiliatesInThirdNotice | |||
testExampleSumTestCase | |||
testRenderAffiliatesInFinalNotice | |||
testRenderAffiliatesInThirdNotice |
--[[
Require all necessary modules for testing the backend.
Author: Derick Alangi (WMF)
]]
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()
-- ------------------------------------------------------------ --
--[[ Pass the method name to invoke and call it. ]]
function suite:invoke(method)
return "{{#invoke:WADP_Backend|" .. method .. "}}"
end
function suite:processFrame(method)
local frame = self.frame
local result = frame:preprocess(suite:invoke(method))
return result
end
-- ------------------------------------------------------------ --
--[[ A simple test to see that this works. ]]
function suite:testExampleSumTestCase()
self:assertEquals(2, 1 + 1, "Expected value didn't match actual.")
end
--[[ Test `render_affiliates_in_third_notice` ]]
function suite:testRenderAffiliatesInThirdNotice()
local results = suite:processFrame('render_affiliates_in_third_notice')
-- Return value should be a string
self:assertEquals('string', type(results))
-- If the string has affiliates, the length should
-- should be greater than zero and contain some specific
-- strings that we can use to assert.
if #results > 0 then
self:assertStringContains('User Group', results)
self:assertStringContains('Wikimedia', results)
else
self:assertEquals(
'No affiliates are in third notice at the moment.',
results
)
end
end
--[[ Test `count_affiliates_in_third_notice` ]]
function suite:testCountAffiliatesInThirdNotice()
local results = suite:processFrame('count_affiliates_in_third_notice')
self:assertTrue(
tonumber(results) >= 0,
"Number of affiliates in third notice is not a valid count."
)
end
--[[ Test `render_affiliates_in_final_notice()` ]]
function suite:testRenderAffiliatesInFinalNotice()
local results = suite:processFrame('render_affiliates_in_final_notice')
-- Return value should be a string
self:assertEquals('string', type(results))
-- If the string has affiliates, the length should
-- should be greater than zero and contain some specific
-- strings that we can use to assert.
if #results > 0 then
self:assertStringContains('User Group', results)
self:assertStringContains('Wikimedia', results)
else
self:assertEquals(
'No affiliates are in final notice at the moment.',
results
)
end
end
--[[ Test `count_affiliates_in_final_notice()` ]]
function suite:testCountAffiliatesInFinalNotice()
local results = suite:processFrame('count_affiliates_in_final_notice')
self:assertTrue(
tonumber(results) >= 0,
"Number of affiliates in final notice is not a valid count."
)
end
return suite