Skip to content

Commit

Permalink
#138 another test
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Sep 26, 2024
1 parent 27e908f commit 9fcf70a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ GEM
net-http
faraday-retry (2.2.1)
faraday (~> 2.0)
fbe (0.0.71)
fbe (0.0.72)
backtrace (> 0)
decoor (> 0)
factbase (> 0)
Expand Down
48 changes: 48 additions & 0 deletions test/pages/test_awards.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,54 @@ def test_payables
assert_equal('55', xml.xpath('/td/text()').to_s, xml)
end

def test_payables_with_few_reconciliations
xml = xslt(
"<xsl:copy-of select=\"z:payables('dude')\"/>",
"
<fb>
<f>
<what>reconciliation</what>
<when>#{(Time.now - (100 * 60 * 60)).utc.iso8601}</when>
<since>#{(Time.now - (200 * 60 * 60)).utc.iso8601}</since>
<who_name>dude</who_name>
<awarded>400</awarded>
<payout>230</payout>
<balance>-120</balance>
</f>
<f>
<what>reconciliation</what>
<when>#{(Time.now - (60 * 60)).utc.iso8601}</when>
<since>#{(Time.now - (50 * 60 * 60)).utc.iso8601}</since>
<who_name>dude</who_name>
<awarded>100</awarded>
<payout>70</payout>
<balance>30</balance>
</f>
<f>
<is_human>1</is_human>
<when>#{(Time.now - (10 * 60 * 60)).utc.iso8601}</when>
<who_name>dude</who_name>
<award>40</award>
</f>
<f>
<is_human>1</is_human>
<when>#{(Time.now - (10 * 60 * 60)).utc.iso8601}</when>
<who_name>dude</who_name>
<award>60</award>
</f>
<f>
<is_human>1</is_human>
<when>#{Time.now.utc.iso8601}</when>
<who_name>dude</who_name>
<award>25</award>
</f>
</fb>
",
'today' => (Time.now - (10 * 60 * 60)).utc.iso8601
)
assert_equal('55', xml.xpath('/td/text()').to_s, xml)
end

def test_monday
xml = xslt(
'<r><xsl:value-of select="z:monday(1)"/></r>',
Expand Down
16 changes: 14 additions & 2 deletions xsl/awards.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,34 @@ SOFTWARE.
<xsl:variable name="facts" select="$fb/f[award and xs:dateTime(when) &gt; $since and is_human = 1]"/>
<xsl:function name="z:monday" as="xs:date">
<!--
Takes week number (e.g. 4) and returns ISO-8601 date of the
Monday of this week. Weeks counting starts from $today.
Takes week number (e.g. 4) and returns ISO-8601 date of the
Monday of this week. Weeks counting starts from the n-th week
before $today (total number of weeks is specified in
the "days_of_running_balance" property of the "pmp/hr" fact. Thus,
if the week number is 2 and there are 56 days of running balance, it is
the 7th week back in the past from today.
-->
<xsl:param name="week" as="xs:integer"/>
<xsl:variable name="d" select="xs:dateTime($today) - xs:dayTimeDuration(concat('P', ($weeks - $week) * 7, 'D'))"/>
<xsl:variable name="dow" select="xs:integer(format-date(xs:date($d), '[F1]'))"/>
<xsl:value-of select="xs:date($d) - xs:dayTimeDuration(concat('P', $dow - 1, 'D'))"/>
</xsl:function>
<xsl:function name="z:in-week" as="xs:boolean">
<!--
Takes date and week number (e.g. 4) and returns 'true' if the date is
inside the week. Weeks counting starts from the n-th week before today.
-->
<xsl:param name="when" as="xs:string"/>
<xsl:param name="week" as="xs:integer"/>
<xsl:variable name="monday" select="xs:dateTime(z:monday($week))"/>
<xsl:variable name="sunday" select="$monday + xs:dayTimeDuration('P7D')"/>
<xsl:value-of select="xs:dateTime($when) &gt; $monday and xs:dateTime($when) &lt; $sunday"/>
</xsl:function>
<xsl:function name="z:payables">
<!--
Calculates the amount to be paid to a user, according to the information
in current awards and previously posted "reconciliation" facts.
-->
<xsl:param name="name"/>
<xsl:variable name="rec" select="$fb/f[what='reconciliation' and who_name=$name][last()]"/>
<xsl:choose>
Expand Down

0 comments on commit 9fcf70a

Please sign in to comment.