Skip to content

Commit

Permalink
[DAT-3177] adds on test
Browse files Browse the repository at this point in the history
  • Loading branch information
Maereg Sorri committed Sep 26, 2023
1 parent a598bc1 commit 03da75d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/modules/main/services/setupNamespace.service.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {getJson, postJson } from "@pepfar-react-lib/datim-api";
import {getJson, postJson, postEmpty } from "@pepfar-react-lib/datim-api";
import {getKeyUid, shareKey} from "../../shared/services/shareKey.service";

const config = require('../../../config/config.json');

async function addNamespaceConfig(datastoreNamespace, onlyOpenToSuperUsersKey) {
const data = { [onlyOpenToSuperUsersKey]: false };
await postJson(`/dataStore/${datastoreNamespace}/configuration`, data);
await postEmpty('/maintenance/cache');
const configKeyUid = await getKeyUid('configuration');
await shareKey(configKeyUid, 'r-------');
}
Expand All @@ -21,5 +22,5 @@ async function checkDataStore(){
export async function connectToDataStore(){
if(await checkDataStore()) return;
const {datastoreNamespace, onlyOpenToSuperUsersKey} = config;
await addNamespaceConfig(datastoreNamespace, onlyOpenToSuperUsersKey);
await addNamespaceConfig(datastoreNamespace, onlyOpenToSuperUsersKey);
}
5 changes: 5 additions & 0 deletions src/test/01.dataStoreInit.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const dataStoreCreateResponse = {"httpStatus":"Created","httpStatusCode":201,"st
const metaDataResponse = {"id":"metadataId1"};
const keyShareStatus = {"object": {publicAccess: "rw------"}}
const keyShareResponse = {"httpStatus":"OK","httpStatusCode":200,"status":"OK","message":"Access control set"};
const clearCacheResponse = {"httpStatus":"OK","httpStatusCode":204,"status":"OK"};

test(`DataStoreInit > Empty`, async ()=>{
dataStoreExists(false);
Expand All @@ -17,7 +18,11 @@ test(`DataStoreInit > Empty`, async ()=>{
let sharing = registerSendMock('/sharing?type=dataStore&id=metadataId1',keyShareResponse).then((response)=>{
expect(response).toStrictEqual({"object":{"id":"metadataId1","publicAccess":"r-------"}});
})
let clearCache = registerSendMock('/maintenance/cache',clearCacheResponse).then((request)=>{
expect(request).toStrictEqual(null);
})
await connectToDataStore();
await dataStore;
await sharing;
await clearCache;
})

0 comments on commit 03da75d

Please # to comment.