Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Added unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Aashir Siddiqui <[email protected]>
  • Loading branch information
aashir21 committed Oct 29, 2024
1 parent 5498027 commit 45df981
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private AuthDBNameViewDesign parseTokenDesignFromJson(String docJson) throws Cou
return tableDesign;
}

private boolean updateDesignDocToDesiredDesignDoc(AuthDBNameViewDesign tableDesign, String dbName) {
protected boolean updateDesignDocToDesiredDesignDoc(AuthDBNameViewDesign tableDesign, String dbName) {
boolean isUpdated = false;

if (tableDesign.views == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
package dev.galasa.auth.couchdb.internal;

import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.net.URI;
import java.util.ArrayList;
Expand Down Expand Up @@ -520,5 +524,43 @@ public void testCheckCouchdbDatabaseIsValidWithUpdateDesignDocResponseThrowsErro
assertThat(thrown).isNotNull();
assertThat(thrown.getMessage()).contains("Update of galasa_tokens design");
}

// Test when all fields are null and dbName is TOKENS_DATABASE_NAME
@Test
public void testAllFieldsNull_TokensDatabase() {
AuthDBNameViewDesign tableDesign = new AuthDBNameViewDesign();
String dbName = CouchdbAuthStore.TOKENS_DATABASE_NAME;

CouchdbAuthStoreValidator validator = new CouchdbAuthStoreValidator();

boolean isUpdated = validator.updateDesignDocToDesiredDesignDoc(tableDesign, dbName);

String DB_TABLE_TOKENS_DESIGN = "function (doc) { if (doc.owner && doc.owner.loginId) {emit(doc.owner.loginId, doc); } }";

assertTrue(isUpdated);
assertNotNull(tableDesign.views);
assertNotNull(tableDesign.views.loginIdView);
assertEquals(DB_TABLE_TOKENS_DESIGN, tableDesign.views.loginIdView.map);
assertEquals("javascript", tableDesign.language);
}

// Test when all fields are null and dbName is not TOKENS_DATABASE_NAME
@Test
public void testAllFieldsNull_OtherDatabase() {
AuthDBNameViewDesign tableDesign = new AuthDBNameViewDesign();
String dbName = CouchdbAuthStore.USERS_DATABASE_NAME;

CouchdbAuthStoreValidator validator = new CouchdbAuthStoreValidator();

boolean isUpdated = validator.updateDesignDocToDesiredDesignDoc(tableDesign, dbName);

String DB_TABLE_USERS_DESIGN = "function (doc) { if (doc['login-id']) { emit(doc['login-id'], doc); } }";

assertTrue(isUpdated);
assertNotNull(tableDesign.views);
assertNotNull(tableDesign.views.loginIdView);
assertEquals(DB_TABLE_USERS_DESIGN, tableDesign.views.loginIdView.map);
assertEquals("javascript", tableDesign.language);
}

}

0 comments on commit 45df981

Please sign in to comment.