Skip to content

Commit 698fb5a

Browse files
test(deleteReferences): Add tests for source inline primary key
1 parent 180ff26 commit 698fb5a

File tree

3 files changed

+164
-62
lines changed

3 files changed

+164
-62
lines changed

test/functions/index.js

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports.replicateMasterToDetail = integrify({
4242
module.exports.deleteReferencesToMaster = integrify({
4343
rule: 'DELETE_REFERENCES',
4444
source: {
45-
collection: 'master',
45+
collection: 'master/{masterId}',
4646
},
4747
targets: [
4848
{
@@ -65,16 +65,16 @@ module.exports.deleteReferencesToMaster = integrify({
6565
module.exports.deleteReferencesWithMasterParam = integrify({
6666
rule: 'DELETE_REFERENCES',
6767
source: {
68-
collection: 'master',
68+
collection: 'master/{primaryKey}',
6969
},
7070
targets: [
7171
{
7272
collection: 'detail1',
73-
foreignKey: 'masterId',
73+
foreignKey: 'primaryKey',
7474
},
7575
{
76-
collection: 'somecoll/$masterId/detail2',
77-
foreignKey: 'masterId',
76+
collection: 'somecoll/$primaryKey/detail2',
77+
foreignKey: 'primaryKey',
7878
},
7979
],
8080
hooks: {
@@ -90,16 +90,16 @@ module.exports.deleteReferencesWithMasterParam = integrify({
9090
module.exports.deleteReferencesWithSnapshotFields = integrify({
9191
rule: 'DELETE_REFERENCES',
9292
source: {
93-
collection: 'master',
93+
collection: 'master/{anotherId}',
9494
},
9595
targets: [
9696
{
9797
collection: 'detail1',
98-
foreignKey: 'masterId',
98+
foreignKey: 'anotherId',
9999
},
100100
{
101101
collection: 'somecoll/$testId/detail2',
102-
foreignKey: 'masterId',
102+
foreignKey: 'anotherId',
103103
},
104104
],
105105
hooks: {
@@ -112,19 +112,40 @@ module.exports.deleteReferencesWithSnapshotFields = integrify({
112112
},
113113
});
114114

115-
module.exports.deleteReferencesWithMissingFields = integrify({
115+
module.exports.deleteReferencesWithMissingKey = integrify({
116116
rule: 'DELETE_REFERENCES',
117117
source: {
118118
collection: 'master',
119119
},
120120
targets: [
121121
{
122122
collection: 'detail1',
123-
foreignKey: 'masterId',
123+
foreignKey: 'randomId',
124+
},
125+
],
126+
hooks: {
127+
pre: (snap, context) => {
128+
setState({
129+
snap,
130+
context,
131+
});
132+
},
133+
},
134+
});
135+
136+
module.exports.deleteReferencesWithMissingFields = integrify({
137+
rule: 'DELETE_REFERENCES',
138+
source: {
139+
collection: 'master/{randomId}',
140+
},
141+
targets: [
142+
{
143+
collection: 'detail1',
144+
foreignKey: 'randomId',
124145
},
125146
{
126147
collection: 'somecoll/$testId/detail2',
127-
foreignKey: 'masterId',
148+
foreignKey: 'randomId',
128149
},
129150
],
130151
hooks: {

test/functions/integrify.rules.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = [
3131
rule: 'DELETE_REFERENCES',
3232
name: 'deleteReferencesToMaster',
3333
source: {
34-
collection: 'master',
34+
collection: 'master/{masterId}',
3535
},
3636
targets: [
3737
{
@@ -49,50 +49,63 @@ module.exports = [
4949
rule: 'DELETE_REFERENCES',
5050
name: 'deleteReferencesWithMasterParam',
5151
source: {
52-
collection: 'master',
52+
collection: 'master/{primaryKey}',
5353
},
5454
targets: [
5555
{
5656
collection: 'detail1',
57-
foreignKey: 'masterId',
57+
foreignKey: 'primaryKey',
5858
},
5959
{
60-
collection: 'somecoll/$masterId/detail2',
61-
foreignKey: 'masterId',
60+
collection: 'somecoll/$primaryKey/detail2',
61+
foreignKey: 'primaryKey',
6262
},
6363
],
6464
},
6565
{
6666
rule: 'DELETE_REFERENCES',
6767
name: 'deleteReferencesWithSnapshotFields',
6868
source: {
69-
collection: 'master',
69+
collection: 'master/{anotherId}',
7070
},
7171
targets: [
7272
{
7373
collection: 'detail1',
74-
foreignKey: 'masterId',
74+
foreignKey: 'anotherId',
7575
},
7676
{
7777
collection: 'somecoll/$testId/detail2',
78-
foreignKey: 'masterId',
78+
foreignKey: 'anotherId',
7979
},
8080
],
8181
},
8282
{
8383
rule: 'DELETE_REFERENCES',
84-
name: 'deleteReferencesWithMissingFields',
84+
name: 'deleteReferencesWithMissingKey',
8585
source: {
8686
collection: 'master',
8787
},
8888
targets: [
8989
{
9090
collection: 'detail1',
91-
foreignKey: 'masterId',
91+
foreignKey: 'randomId',
92+
},
93+
],
94+
},
95+
{
96+
rule: 'DELETE_REFERENCES',
97+
name: 'deleteReferencesWithMissingFields',
98+
source: {
99+
collection: 'master/{randomId}',
100+
},
101+
targets: [
102+
{
103+
collection: 'detail1',
104+
foreignKey: 'randomId',
92105
},
93106
{
94107
collection: 'somecoll/$testId/detail2',
95-
foreignKey: 'masterId',
108+
foreignKey: 'randomId',
96109
},
97110
],
98111
},

0 commit comments

Comments
 (0)