Skip to content

Commit 4eff987

Browse files
committed
started testing for #17
adapted get app method for testing defined test for prepares
1 parent 9a0d315 commit 4eff987

File tree

5 files changed

+161
-16
lines changed

5 files changed

+161
-16
lines changed

functions/getter.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
const admin = require('firebase-admin');
2+
const serviceAccount = require('./ottaaproject-flutter-firebase-adminsdk-z2x83-b744263584.json');
3+
4+
function getDbRef () {
5+
try{
6+
return admin.app('realiser')
7+
} catch (e){
8+
admin.initializeApp({
9+
credential: admin.credential.cert(serviceAccount),
10+
databaseURL: "https://ottaaproject-realiser-lexicons.firebaseio.com/",
11+
}, 'realiser');
12+
return admin.app('realiser')
13+
}
14+
}
115

216
class dbGetter{
317
static alreadyData = {};
@@ -20,4 +34,4 @@ class dbGetter{
2034
}
2135
}
2236

23-
module.exports = { dbGetter }
37+
module.exports = { dbGetter, getDbRef }

functions/methods.js

+2-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
1-
const admin = require('firebase-admin');
2-
const serviceAccount = require('./ottaaproject-flutter-firebase-adminsdk-z2x83-b744263584.json');
3-
const { dbGetter } = require('./getter.js')
4-
5-
try{
6-
admin.app('realiser')
7-
} catch (e){
8-
admin.initializeApp({
9-
credential: admin.credential.cert(serviceAccount),
10-
databaseURL: "https://ottaaproject-realiser-lexicons.firebaseio.com/",
11-
}, 'realiser');
12-
}
1+
const { dbGetter, getDbRef } = require('./getter.js')
132

14-
const rt = admin.app('realiser').database()
3+
const rt = getDbRef().database()
154

165
async function addLexiconData(path, data){
176
const newDataRef = rt.ref(path)

functions/package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"shell": "firebase functions:shell",
77
"start": "npm run shell",
88
"deploy": "firebase deploy --only functions",
9-
"logs": "firebase functions:log"
9+
"logs": "firebase functions:log",
10+
"test": "mocha tests/prepares.test.js"
1011
},
1112
"engines": {
1213
"node": "16"
@@ -19,7 +20,9 @@
1920
"swagger-ui-express": "^4.6.0"
2021
},
2122
"devDependencies": {
22-
"firebase-functions-test": "^0.2.0"
23+
"chai": "^4.3.7",
24+
"firebase-functions-test": "^0.2.0",
25+
"mocha": "^10.1.0"
2326
},
2427
"private": true
2528
}

functions/tests/dependencies.test.js

Whitespace-only changes.

functions/tests/prepares.test.js

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
const expect = require('chai').expect
2+
3+
describe('Testing prepare NOUN methods', () => {
4+
before(() => {
5+
const { getDbRef } = require('../getter.js')
6+
this.langRef = getDbRef().database().ref('es')
7+
this.prepareMeta = require('../prepares.js').prepareMeta;
8+
})
9+
10+
it('Should split words in definitive MISC', async () => {
11+
const testObj = {
12+
words: ['casa de un amigo'],
13+
types: ['NOUN'],
14+
type: 'NOUN',
15+
props: {},
16+
meta: {},
17+
composed: true
18+
}
19+
20+
const resultObj = await this.prepareMeta(testObj, this.langRef)
21+
expect(resultObj.words.length).to.eql(4)
22+
expect(resultObj.types.length).to.eql(4)
23+
expect(resultObj.types).to.include('NOUN')
24+
expect(resultObj.types).to.include('PREP')
25+
expect(resultObj.types).to.include('ART')
26+
})
27+
28+
it('Should mark NOUN type as SUBJ for later processing', async () => {
29+
const testObj = {
30+
words: ['casa de un amigo'],
31+
types: ['NOUN'],
32+
type: 'NOUN',
33+
props: {},
34+
meta: {},
35+
composed: true
36+
}
37+
38+
this.prepareMeta(testObj, this.langRef)
39+
.then((resultObj) => {
40+
expect(resultObj.type).to.equal('SUBJ')
41+
})
42+
})
43+
44+
it('Should properly detect/define gender', async () => {
45+
const testObj = {
46+
words: ['abuelo', 'y', 'mamá'],
47+
types: ['NOUN', 'CON', 'NOUN'],
48+
type: 'NOUN',
49+
props: {},
50+
meta: {},
51+
composed: true
52+
}
53+
54+
const resultObj = await this.prepareMeta(testObj, this.langRef)
55+
expect(resultObj.meta.PERSON).to.equal('ellos')
56+
expect(resultObj.meta.GENDER).to.equal('ellos')
57+
expect(resultObj.genders).to.eql(['él', 'ella'])
58+
})
59+
})
60+
61+
describe('Testing prepare SUBJ methods', async () => {
62+
before(() => {
63+
const { getDbRef } = require('../getter.js')
64+
this.langRef = getDbRef().database().ref('es')
65+
this.prepareMeta = require('../prepares.js').prepareMeta;
66+
})
67+
68+
it('Should manage gender', async () => {
69+
const testObj = {
70+
words: ['yo', 'vos', 'mamá', 'y', 'ella'],
71+
types: ['SUBJ', 'SUBJ', 'SUBJ', 'CON', 'SUBJ'],
72+
type: 'SUBJ',
73+
props: {
74+
0: {
75+
gender: 'él'
76+
},
77+
1: {
78+
gender: 'ella'
79+
}
80+
},
81+
meta: {},
82+
composed: true
83+
}
84+
85+
var resultObj;
86+
//Should properly detect/define gender
87+
resultObj = await this.prepareMeta(testObj, this.langRef)
88+
expect(resultObj.meta.PERSON).to.equal('nosotros')
89+
expect(resultObj.meta.GENDER).to.equal('ellos')
90+
expect(resultObj.genders).to.eql(['él', 'ella', 'ella', 'ella']) //eql is deep equality
91+
92+
testObj.props['0'].gender = 'ella'
93+
//Should use plural feminines if all genders are feminine'
94+
resultObj = await this.prepareMeta(testObj, this.langRef)
95+
expect(resultObj.meta.PERSON).to.equal('nosotros')
96+
expect(resultObj.meta.GENDER).to.equal('ellas')
97+
expect(resultObj.genders).to.eql(['ella', 'ella', 'ella', 'ella']) //eql is deep equality
98+
})
99+
})
100+
101+
describe('Testing prepare ADV methods', async () => {
102+
before(() => {
103+
const { getDbRef } = require('../getter.js')
104+
this.langRef = getDbRef().database().ref('es')
105+
this.prepareMeta = require('../prepares.js').prepareMeta;
106+
})
107+
108+
it('Should detect adverbial TIME', async () => {
109+
const testObj = {
110+
words: ['antes'],
111+
types: ['ADV'],
112+
type: 'ADV',
113+
props: {},
114+
meta: {},
115+
composed: true
116+
}
117+
118+
const resultObj = await this.prepareMeta(testObj, this.langRef)
119+
expect(resultObj.meta.TIME).to.equal('pasado')
120+
})
121+
122+
it('Should transform MOD into ADV', async () => {
123+
const testObj = {
124+
words: ['después'],
125+
types: ['MOD'],
126+
type: 'ADV',
127+
props: {},
128+
meta: {},
129+
composed: true
130+
}
131+
132+
const resultObj = await this.prepareMeta(testObj, this.langRef)
133+
expect(resultObj.meta.TIME).to.equal('futuro')
134+
expect(resultObj.types).not.to.include('MOD')
135+
expect(resultObj.types).to.include('ADV')
136+
})
137+
})
138+
139+
//MISSING SOLVE MISC BUT MUST DEFINITIVES MISC ARE NOT DONE YET

0 commit comments

Comments
 (0)