Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DAT-3177] adds on test #10

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
})
Loading