-
Notifications
You must be signed in to change notification settings - Fork 0
/
fireStoreApp.test.js
110 lines (98 loc) · 3.33 KB
/
fireStoreApp.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const { interactWithFirestore } = require('./server/models/firestoreApp');
async function runTests() {
const testData = {
A: "Test A",
B: "12/12/2020",
C: "Test C",
D: "Test D",
E: "Test E",
invoiceDetails: {
"key1": "value1",
"key2": "value2"
}
};
const updateData = {
A: "Updated A",
B: "Updated B"
};
try {
console.time("Total time");
console.log("Starting tests...");
// Create a new document
console.time("Create Document");
const newDocumentId = await interactWithFirestore('writeData', testData);
console.timeEnd("Create Document");
console.log("Created Document ID:", newDocumentId);
if (newDocumentId) {
console.log("PASS");
}else{
console.log("FAIL");
console.log(newDocumentId);
}
// Read the new document
console.time("Read New Document");
const newDocumentData = await interactWithFirestore('readData', { documentId: newDocumentId });
console.timeEnd("Read New Document");
if (newDocumentData) {
console.log("PASS");
}else{
console.log("FAIL");
console.log(newDocumentData);
}
// Update the document
console.time("Updating the document");
var res = await interactWithFirestore('updateData', { documentId: newDocumentId, updateFields: updateData });
console.timeEnd("Updating the document");
if (res) {
console.log("PASS");
}else{
console.log("FAIL");
console.log(res);
}
// Read the updated document
console.time("Reading the updated document: ");
const updatedDocumentData = await interactWithFirestore('readData', { documentId: newDocumentId });
console.timeEnd("Reading the updated document: ");
if (updatedDocumentData) {
console.log("PASS");
}else{
console.log("FAIL");
console.log(updatedDocumentData);
}
// Delete the document
console.time("Delete Document");
const deldata = await interactWithFirestore('deleteData', { documentId: newDocumentId });
console.timeEnd("Delete Document");
if (deldata) {
console.log("PASS");
}else{
console.log("FAIL");
console.log(deldata);
}
// Verify the deletion
try {
console.time("Verify Deletion");
const res = await interactWithFirestore('readData', { documentId: newDocumentId });
console.timeEnd("Verify Deletion");
if(res.toString().includes("not found")){
console.log("PASS");
}else{
console.log("FAIL");
console.log(res);
}
} catch (error) {
if (error.message.includes("not found")) {
console.log("PASS");
}else{
console.log("FAIL");
console.log(error);
}
}
console.log("Tests completed.");
//total time
console.timeEnd("Total time");
} catch (error) {
console.error("An error occurred during the tests:", error);
}
}
runTests().catch(console.error);