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

Commit

Permalink
Merge pull request #283 from galasa-dev/ash-couchdb-view-fix
Browse files Browse the repository at this point in the history
ash couchdb view fix
  • Loading branch information
techcobweb authored Oct 29, 2024
2 parents 5d99d56 + 45df981 commit 6d80007
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
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 All @@ -133,7 +133,7 @@ private boolean updateDesignDocToDesiredDesignDoc(AuthDBNameViewDesign tableDesi

if (tableDesign.views.loginIdView.map == null) {
isUpdated = true;
if(dbName.equals(DB_TABLE_TOKENS_DESIGN)){
if(dbName.equals(CouchdbAuthStore.TOKENS_DATABASE_NAME)){
tableDesign.views.loginIdView.map = DB_TABLE_TOKENS_DESIGN;
}
else{
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 6d80007

Please sign in to comment.