@@ -16,6 +16,7 @@ import {ClientModelAPI} from '../../src/model/clients'
1616import { ContactGroupModelAPI } from '../../src/model/contactGroups'
1717import { MediatorModelAPI } from '../../src/model/mediators'
1818import { UserModelAPI } from '../../src/model/users'
19+ import { PassportModelAPI } from '../../src/model/passport'
1920import * as polling from '../../src/polling'
2021
2122const sampleMetadata = {
@@ -89,6 +90,12 @@ const sampleMetadata = {
8990 groups : [ 'admin' , 'RHIE' ]
9091 }
9192 ] ,
93+ Passports : [
94+ {
95+ 96+ protocol : 'local'
97+ }
98+ ] ,
9299 ContactGroups : [
93100 {
94101 group : 'Group 1' ,
@@ -101,6 +108,11 @@ const sampleMetadata = {
101108 { user : 'User 6' , method : 'email' , maxAlerts : '1 per day' }
102109 ]
103110 }
111+ ] ,
112+ Keystore : [
113+ {
114+ key : 'Key'
115+ }
104116 ]
105117}
106118
@@ -112,6 +124,7 @@ describe('API Integration Tests', () => {
112124 nonRootCookie = ''
113125
114126 before ( async ( ) => {
127+ await PassportModelAPI . deleteMany ( { } )
115128 await promisify ( server . start ) ( { apiPort : SERVER_PORTS . apiPort } )
116129 await testUtils . setupTestUsers ( )
117130 } )
@@ -216,6 +229,17 @@ describe('API Integration Tests', () => {
216229 } )
217230 } )
218231
232+ describe ( 'Passports' , ( ) => {
233+ it ( 'should fetch passports and return status 200' , async ( ) => {
234+ const res = await request ( BASE_URL )
235+ . get ( '/metadata' )
236+ . set ( 'Cookie' , rootCookie )
237+ . expect ( 200 )
238+
239+ res . body [ 0 ] . Passports . length . should . equal ( 2 )
240+ } )
241+ } )
242+
219243 describe ( 'ContactGroups' , ( ) => {
220244 beforeEach ( async ( ) => {
221245 await new ContactGroupModelAPI ( sampleMetadata . ContactGroups [ 0 ] ) . save ( )
@@ -724,10 +748,103 @@ describe('API Integration Tests', () => {
724748 // POST TO VALIDATE METADATA TESTS
725749 describe ( '*validateMetadata' , ( ) => {
726750 beforeEach ( async ( ) => {
751+ await PassportModelAPI . deleteMany ( )
727752 await testUtils . cleanupAllTestUsers ( )
728753 await testUtils . setupTestUsers ( )
729754 } )
730755
756+ const sampleMetadata = {
757+ Channels : [
758+ {
759+ name : 'TestChannel1' ,
760+ urlPattern : 'test/sample' ,
761+ allow : [ 'PoC' , 'Test1' , 'Test2' ] ,
762+ routes : [
763+ { name : 'test route' , host : 'localhost' , port : 9876 , primary : true }
764+ ] ,
765+ txViewAcl : 'group1' ,
766+ updatedBy : {
767+ id : new ObjectId ( ) ,
768+ name : 'Test'
769+ }
770+ }
771+ ] ,
772+ Clients : [
773+ {
774+ clientID : 'YUIAIIIICIIAIA' ,
775+ clientDomain : 'him.jembi.org' ,
776+ name : 'OpenMRS Ishmael instance' ,
777+ roles : [ 'OpenMRS_PoC' , 'PoC' ] ,
778+ passwordHash :
779+ '$2a$10$w8GyqInkl72LMIQNpMM/fenF6VsVukyya.c6fh/GRtrKq05C2.Zgy' ,
780+ certFingerprint :
781+ '23:37:6A:5E:A9:13:A4:8C:66:C5:BB:9F:0E:0D:68:9B:99:80:10:FC'
782+ }
783+ ] ,
784+ Mediators : [
785+ {
786+ urn : 'urn:uuid:EEA84E13-1C92-467C-B0BD-7C480462D1ED' ,
787+ version : '1.0.0' ,
788+ name : 'Save Encounter Mediator' ,
789+ description : 'A mediator for testing' ,
790+ endpoints : [
791+ {
792+ name : 'Save Encounter' ,
793+ host : 'localhost' ,
794+ port : '8005' ,
795+ type : 'http'
796+ }
797+ ] ,
798+ defaultChannelConfig : [
799+ {
800+ name : 'Save Encounter 1' ,
801+ urlPattern : '/encounters' ,
802+ type : 'http' ,
803+ allow : [ ] ,
804+ routes : [
805+ {
806+ name : 'Save Encounter 1' ,
807+ host : 'localhost' ,
808+ port : '8005' ,
809+ type : 'http'
810+ }
811+ ]
812+ }
813+ ]
814+ }
815+ ] ,
816+ Users : [
817+ {
818+ firstname : 'Namey' ,
819+ surname : 'mcTestName' ,
820+ 821+ passwordAlgorithm : 'sha512' ,
822+ passwordHash : '796a5a8e-4e44-4d9f-9e04-c27ec6374ffa' ,
823+ passwordSalt : 'bf93caba-6eec-4c0c-a1a3-d968a7533fd7' ,
824+ groups : [ 'admin' , 'RHIE' ]
825+ }
826+ ] ,
827+ Passports : [
828+ {
829+ 830+ protocol : 'local'
831+ }
832+ ] ,
833+ ContactGroups : [
834+ {
835+ group : 'Group 1' ,
836+ users : [
837+ { user : 'User 1' , method : 'sms' , maxAlerts : 'no max' } ,
838+ { user : 'User 2' , method : 'email' , maxAlerts : '1 per hour' } ,
839+ { user : 'User 3' , method : 'sms' , maxAlerts : '1 per day' } ,
840+ { user : 'User 4' , method : 'email' , maxAlerts : 'no max' } ,
841+ { user : 'User 5' , method : 'sms' , maxAlerts : '1 per hour' } ,
842+ { user : 'User 6' , method : 'email' , maxAlerts : '1 per day' }
843+ ]
844+ }
845+ ]
846+ }
847+
731848 it ( 'should validate metadata and return status 201' , async ( ) => {
732849 const res = await request ( BASE_URL )
733850 . post ( '/metadata/validate' )
@@ -741,7 +858,7 @@ describe('API Integration Tests', () => {
741858 statusCheckObj [ doc . status ] += 1
742859 }
743860
744- statusCheckObj . Valid . should . equal ( 5 )
861+ statusCheckObj . Valid . should . equal ( 6 )
745862 statusCheckObj . Conflict . should . equal ( 0 )
746863 statusCheckObj . Error . should . equal ( 0 )
747864 } )
@@ -762,7 +879,7 @@ describe('API Integration Tests', () => {
762879 statusCheckObj [ doc . status ] += 1
763880 }
764881
765- statusCheckObj . Valid . should . equal ( 4 )
882+ statusCheckObj . Valid . should . equal ( 5 )
766883 statusCheckObj . Conflict . should . equal ( 0 )
767884 statusCheckObj . Error . should . equal ( 1 )
768885 } )
@@ -787,7 +904,7 @@ describe('API Integration Tests', () => {
787904 statusCheckObj [ doc . status ] += 1
788905 }
789906
790- statusCheckObj . Valid . should . equal ( 4 )
907+ statusCheckObj . Valid . should . equal ( 5 )
791908 statusCheckObj . Conflict . should . equal ( 1 )
792909 statusCheckObj . Error . should . equal ( 0 )
793910 ChannelModelAPI . deleteMany ( { } )
0 commit comments