Skip to content

Commit

Permalink
Added APICharityScraperTest test class.
Browse files Browse the repository at this point in the history
Added testclass for the scraper with some test methods.
  • Loading branch information
roaraf committed Feb 27, 2026
1 parent f26ab51 commit ebe1524
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package ntnu.sytemutvikling.team6.models;

import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.URISyntaxException;

import static org.junit.jupiter.api.Assertions.*;

class APICharityScraperTest {
@Test
void connectionToDataBaseShouldReturnTrue() throws IOException, URISyntaxException {
var con = new APICharityScraper();

assertTrue(con.checkConnection(), "Get response should be 200 (success)");
}


@Test
void ParsedJSONShouldHaveCorrectValues() throws IOException, URISyntaxException {
var con = new APICharityScraper();
String JSONData = "[{\"org_number\":\"938419264\",\"name\":\"Misjonsalliansen\",\"status\":\"approved\"," +
"\"url\":\"https:\\/\\/www.innsamlingskontrollen.no\\/organisasjoner\\/misjonsalliansen\\/\"," +
"\"is_pre_approved\":false}]";
var list = con.parseJSON(JSONData);

assertEquals("938419264", list.getFirst().getOrg_number(),
"Parsed organization number should be correct.");
assertEquals("Misjonsalliansen", list.getFirst().getName(),
"Parsed name should be correct");
assertEquals("approved", list.getFirst().getStatus(),
"Parsed status should be correct.");
assertEquals("https://www.innsamlingskontrollen.no/organisasjoner/misjonsalliansen/",
list.getFirst().getUrl(), "Parsed url should be correct.");
assertFalse(list.getFirst().getIs_pre_approved(), "Parsed is_pre_approved boolean should " +
"be correct.");
}

}

0 comments on commit ebe1524

Please sign in to comment.