Skip to content

Commit c4a9c74

Browse files
test(deleteReferences): Remove subcollection test
1 parent aae9256 commit c4a9c74

File tree

1 file changed

+35
-105
lines changed

1 file changed

+35
-105
lines changed

test/unit.test.js

Lines changed: 35 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ const fft = require('firebase-functions-test')(
77
);
88
const test = require('ava');
99
const { integrify } = require('../lib');
10-
const {
11-
replaceReferencesWith,
12-
getPrimaryKey,
13-
isSubCollection,
14-
} = require('../lib/common');
10+
const { replaceReferencesWith, getPrimaryKey } = require('../lib/common');
1511
const { getState, setState } = require('./functions/stateMachine');
1612

1713
const admin = require('firebase-admin');
@@ -57,8 +53,8 @@ testsuites.forEach(testsuite => {
5753
});
5854
test(`[${name}] test get primary key`, async t =>
5955
testPrimaryKey(sut, t, name));
60-
test(`[${name}] test sub-collection check`, async t =>
61-
testSubCollection(sut, t, name));
56+
// test(`[${name}] test sub-collection check`, async t =>
57+
// testSubCollection(sut, t, name));
6258
test(`[${name}] test target collection parameter swap`, async t =>
6359
testTargetVariableSwap(sut, t, name));
6460
test(`[${name}] test replicate attributes`, async t =>
@@ -78,8 +74,8 @@ testsuites.forEach(testsuite => {
7874

7975
test(`[${name}] test delete all sub-collections in target reference`, async t =>
8076
testDeleteAllSubCollections(sut, t, name));
81-
test(`[${name}] test delete all sub-collections in target reference error`, async t =>
82-
testDeleteAllSubCollectionsError(sut, t, name));
77+
// test(`[${name}] test delete all sub-collections in target reference error`, async t =>
78+
// testDeleteAllSubCollectionsError(sut, t, name));
8379

8480
test(`[${name}] test delete missing arguments error`, async t =>
8581
testDeleteMissingArgumentsError(sut, t, name));
@@ -108,43 +104,43 @@ async function testPrimaryKey(sut, t, name) {
108104
await t.pass();
109105
}
110106

111-
async function testSubCollection(sut, t, name) {
112-
// Test zero key
113-
let result = isSubCollection('');
114-
t.false(result);
107+
// async function testSubCollection(sut, t, name) {
108+
// // Test zero key
109+
// let result = isSubCollection('');
110+
// t.false(result);
115111

116-
// Test one key
117-
result = isSubCollection('collection');
118-
t.false(result);
112+
// // Test one key
113+
// result = isSubCollection('collection');
114+
// t.false(result);
119115

120-
// Test two keys
121-
result = isSubCollection('collection1/collection2');
122-
t.false(result);
116+
// // Test two keys
117+
// result = isSubCollection('collection1/collection2');
118+
// t.false(result);
123119

124-
// Test three keys
125-
result = isSubCollection('collection1/collection2/collection3');
126-
t.true(result);
120+
// // Test three keys
121+
// result = isSubCollection('collection1/collection2/collection3');
122+
// t.true(result);
127123

128-
// Test four keys
129-
result = isSubCollection('collection1/collection2/collection3/collection4');
130-
t.false(result);
124+
// // Test four keys
125+
// result = isSubCollection('collection1/collection2/collection3/collection4');
126+
// t.false(result);
131127

132-
// Test five keys
133-
result = isSubCollection(
134-
'collection1/collection2/collection3/collection4/collection5'
135-
);
136-
t.true(result);
128+
// // Test five keys
129+
// result = isSubCollection(
130+
// 'collection1/collection2/collection3/collection4/collection5'
131+
// );
132+
// t.true(result);
137133

138-
// Check incorrect format of collection
139-
result = isSubCollection('collection1//');
140-
t.false(result);
141-
result = isSubCollection('//collection1//');
142-
t.false(result);
143-
result = isSubCollection('collection1///collection2///collection3');
144-
t.true(result);
134+
// // Check incorrect format of collection
135+
// result = isSubCollection('collection1//');
136+
// t.false(result);
137+
// result = isSubCollection('//collection1//');
138+
// t.false(result);
139+
// result = isSubCollection('collection1///collection2///collection3');
140+
// t.true(result);
145141

146-
await t.pass();
147-
}
142+
// await t.pass();
143+
// }
148144

149145
async function testTargetVariableSwap(sut, t, name) {
150146
// test no fields
@@ -646,72 +642,6 @@ async function testDeleteAllSubCollections(sut, t, name) {
646642
t.pass();
647643
}
648644

649-
async function testDeleteAllSubCollectionsError(sut, t, name) {
650-
// Create some docs referencing master doc
651-
const randomId = makeid();
652-
const testId = makeid();
653-
const nestedDocRef = db.collection('somecoll').doc(testId);
654-
await nestedDocRef.set({
655-
x: 1,
656-
});
657-
await nestedDocRef.collection('detail2').add({
658-
randomId: randomId,
659-
});
660-
await assertQuerySizeEventually(
661-
db
662-
.collection('somecoll')
663-
.doc(testId)
664-
.collection('detail2')
665-
.where('randomId', '==', randomId),
666-
1
667-
);
668-
669-
// Trigger function to delete references
670-
const snap = fft.firestore.makeDocumentSnapshot(
671-
{
672-
testId,
673-
},
674-
`master/${randomId}`
675-
);
676-
const wrapped = fft.wrap(sut.deleteReferencesDeleteAllSubCollectionErrors);
677-
setState({
678-
snap: null,
679-
context: null,
680-
});
681-
const error = await t.throwsAsync(async () => {
682-
await wrapped(snap, {
683-
params: {
684-
randomId: randomId,
685-
testId: testId,
686-
},
687-
});
688-
});
689-
t.is(
690-
error.message,
691-
`integrify: [master/details] is an invalid sub-collection`
692-
);
693-
694-
// Assert pre-hook was called (only for rules-in-situ)
695-
if (name === 'rules-in-situ') {
696-
const state = getState();
697-
t.truthy(state.snap);
698-
t.truthy(state.context);
699-
t.is(state.context.params.randomId, randomId);
700-
}
701-
702-
// Assert referencing docs were deleted
703-
await assertQuerySizeEventually(
704-
db
705-
.collection('somecoll')
706-
.doc(testId)
707-
.collection('detail2')
708-
.where('randomId', '==', randomId),
709-
1
710-
);
711-
712-
t.pass();
713-
}
714-
715645
async function testDeleteMissingArgumentsError(sut, t, name) {
716646
// Create some docs referencing master doc
717647
const randomId = makeid();

0 commit comments

Comments
 (0)