]> WPIA git - gigi.git/commitdiff
fix: counting of nucleus verifications
authorFelix Dörre <felix@dogcraft.de>
Fri, 30 Dec 2016 09:44:06 +0000 (10:44 +0100)
committerFelix Dörre <felix@dogcraft.de>
Tue, 3 Jan 2017 11:04:00 +0000 (12:04 +0100)
Change-Id: I4a76e579049d822d3280ffc4570f5f2248cac9a4

src/org/cacert/gigi/dbObjects/Name.java
src/org/cacert/gigi/dbObjects/User.java
tests/org/cacert/gigi/util/TestNotary.java

index dc1c0376177a7147084fa59d773b2daf70663024..df9e1ff6f19660005f115cd63b23624bba06697b 100644 (file)
@@ -385,7 +385,7 @@ public class Name implements Outputable, IdCachable {
     }
 
     public int getAssurancePoints() {
-        try (GigiPreparedStatement query = new GigiPreparedStatement("SELECT SUM(`points`) FROM (SELECT DISTINCT ON (`from`) `points` FROM `notary` WHERE `to`=? AND `deleted` IS NULL AND (`expire` IS NULL OR `expire` > CURRENT_TIMESTAMP) ORDER BY `from`, `when` DESC) AS p")) {
+        try (GigiPreparedStatement query = new GigiPreparedStatement("SELECT SUM(`points`) FROM (SELECT DISTINCT ON (`from`, `method`) `points` FROM `notary` WHERE `to`=? AND `deleted` IS NULL AND (`expire` IS NULL OR `expire` > CURRENT_TIMESTAMP) ORDER BY `from`, `method`, `when` DESC) AS p")) {
             query.setInt(1, getId());
 
             GigiResultSet rs = query.executeQuery();
index b4bfcc1cece2bea5b14f21505256b7dbd68c9e95..fa02012ad1edf942d3cac5ea2790993f8568e2c2 100644 (file)
@@ -238,7 +238,7 @@ public class User extends CertificateOwner {
     }
 
     public int getAssurancePoints() {
-        try (GigiPreparedStatement query = new GigiPreparedStatement("SELECT SUM(lastpoints) FROM ( SELECT DISTINCT ON (`from`) `from`, `points` as lastpoints FROM `notary` INNER JOIN `names` ON `names`.`id`=`to` WHERE `notary`.`deleted` is NULL AND (`expire` IS NULL OR `expire` > CURRENT_TIMESTAMP) AND `names`.`uid` = ? ORDER BY `from`, `when` DESC) as p")) {
+        try (GigiPreparedStatement query = new GigiPreparedStatement("SELECT SUM(lastpoints) FROM ( SELECT DISTINCT ON (`from`, `method`) `from`, `points` as lastpoints FROM `notary` INNER JOIN `names` ON `names`.`id`=`to` WHERE `notary`.`deleted` is NULL AND (`expire` IS NULL OR `expire` > CURRENT_TIMESTAMP) AND `names`.`uid` = ? ORDER BY `from`, `method`, `when` DESC) as p")) {
             query.setInt(1, getId());
 
             GigiResultSet rs = query.executeQuery();
index fd3e62ef6e073855fcf2353c4a18aabd93ad952c..e8f709daf40db9ef0c55e3f3fdd86a671d042999 100644 (file)
@@ -2,6 +2,7 @@ package org.cacert.gigi.util;
 
 import static org.junit.Assert.*;
 
+import java.io.IOException;
 import java.sql.SQLException;
 import java.util.Date;
 
@@ -10,6 +11,10 @@ import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.dbObjects.Assurance.AssuranceType;
 import org.cacert.gigi.dbObjects.Country;
 import org.cacert.gigi.dbObjects.Country.CountryCodeType;
+import org.cacert.gigi.dbObjects.Group;
+import org.cacert.gigi.dbObjects.Name;
+import org.cacert.gigi.dbObjects.NamePart;
+import org.cacert.gigi.dbObjects.NamePart.NamePartType;
 import org.cacert.gigi.dbObjects.ObjectCache;
 import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.output.DateSelector;
@@ -123,4 +128,26 @@ public class TestNotary extends BusinessTest {
         assuranceFail(assuranceUser, assuree, 10, "notary-junit-test", validVerificationDateString());
 
     }
+
+    @Test
+    public void testNucleus() throws SQLException, GigiApiException, IOException {
+        User assuranceUser = User.getById(createAssuranceUser("fn", "ln", createUniqueName() + "@example.org", TEST_PASSWORD));
+        assuranceUser.grantGroup(getSupporter(), Group.NUCLEUS_ASSURER);
+        User assuree = User.getById(createVerifiedUser("fn", "ln", createUniqueName() + "@example.org", TEST_PASSWORD));
+        Name n1 = assuree.getPreferredName();
+        Name n2 = new Name(assuree, new NamePart(NamePartType.FIRST_NAME, "F2"), new NamePart(NamePartType.LAST_NAME, "L2"));
+
+        assertEquals(0, assuree.getExperiencePoints());
+        assertEquals(User.EXPERIENCE_POINTS, assuranceUser.getExperiencePoints());
+        assertEquals(0, assuree.getAssurancePoints());
+        assertEquals(0, n2.getAssurancePoints());
+        Notary.assureAll(assuranceUser, assuree, assuree.getDoB(), 50, "notary-junit-test", validVerificationDateString(), AssuranceType.NUCLEUS, new Name[] {
+                n1, n2
+        }, DE);
+        assertEquals(0, assuree.getExperiencePoints());
+        assertEquals(2 * User.EXPERIENCE_POINTS, assuranceUser.getExperiencePoints());
+        assertEquals(50, assuree.getAssurancePoints());
+        assertEquals(50, n1.getAssurancePoints());
+        assertEquals(50, n2.getAssurancePoints());
+    }
 }