Skip to content

Commit 742e17a

Browse files
authored
test(firestore): update nested fields test to reflect backend change (#9717)
The backend now supports nested field modification in the addFields and select changes. All aliases with a `.` are now treated as a nested field path. This change updates the tests to reflect this new behaviour.
1 parent 3ddfe88 commit 742e17a

2 files changed

Lines changed: 100 additions & 81 deletions

File tree

packages/firestore/test/integration/api/pipeline.test.ts

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,10 +2349,13 @@ apiDescribe.skipClassic('Pipelines', persistence => {
23492349
const err = e as FirebaseError;
23502350
expect(err['code']).to.equal('invalid-argument');
23512351
expect(typeof err['message']).to.equal('string');
2352+
2353+
expect(err['message']).to.match(
2354+
/Expected fields to be MAP_VALUE, but was FIELD_REFERENCE_VALUE./
2355+
);
23522356
}
23532357
});
23542358
});
2355-
23562359
describe('function expressions', () => {
23572360
it('logical max works', async () => {
23582361
const snapshot = await execute(
@@ -2362,17 +2365,17 @@ apiDescribe.skipClassic('Pipelines', persistence => {
23622365
.select(
23632366
'title',
23642367
logicalMaximum(constant(1960), field('published'), 1961).as(
2365-
'published-safe'
2368+
'publishedSafe'
23662369
)
23672370
)
23682371
.sort(field('title').ascending())
23692372
.limit(3)
23702373
);
23712374
expectResults(
23722375
snapshot,
2373-
{ title: '1984', 'published-safe': 1961 },
2374-
{ title: 'Crime and Punishment', 'published-safe': 1961 },
2375-
{ title: 'Dune', 'published-safe': 1965 }
2376+
{ title: '1984', 'publishedSafe': 1961 },
2377+
{ title: 'Crime and Punishment', 'publishedSafe': 1961 },
2378+
{ title: 'Dune', 'publishedSafe': 1965 }
23762379
);
23772380
});
23782381

@@ -2384,17 +2387,17 @@ apiDescribe.skipClassic('Pipelines', persistence => {
23842387
.select(
23852388
'title',
23862389
logicalMinimum(constant(1960), field('published'), 1961).as(
2387-
'published-safe'
2390+
'publishedSafe'
23882391
)
23892392
)
23902393
.sort(field('title').ascending())
23912394
.limit(3)
23922395
);
23932396
expectResults(
23942397
snapshot,
2395-
{ title: '1984', 'published-safe': 1949 },
2396-
{ title: 'Crime and Punishment', 'published-safe': 1866 },
2397-
{ title: 'Dune', 'published-safe': 1960 }
2398+
{ title: '1984', 'publishedSafe': 1949 },
2399+
{ title: 'Crime and Punishment', 'publishedSafe': 1866 },
2400+
{ title: 'Dune', 'publishedSafe': 1960 }
23982401
);
23992402
});
24002403

@@ -2409,7 +2412,7 @@ apiDescribe.skipClassic('Pipelines', persistence => {
24092412
lessThan(field('published'), 1960),
24102413
constant(1960),
24112414
field('published')
2412-
).as('published-safe'),
2415+
).as('publishedSafe'),
24132416
field('rating')
24142417
.greaterThanOrEqual(4.5)
24152418
.conditional(constant('great'), constant('good'))
@@ -2420,13 +2423,13 @@ apiDescribe.skipClassic('Pipelines', persistence => {
24202423
);
24212424
expectResults(
24222425
snapshot,
2423-
{ title: '1984', 'published-safe': 1960, rating: 'good' },
2426+
{ title: '1984', 'publishedSafe': 1960, rating: 'good' },
24242427
{
24252428
title: 'Crime and Punishment',
2426-
'published-safe': 1960,
2429+
'publishedSafe': 1960,
24272430
rating: 'good'
24282431
},
2429-
{ title: 'Dune', 'published-safe': 1965, rating: 'great' }
2432+
{ title: 'Dune', 'publishedSafe': 1965, rating: 'great' }
24302433
);
24312434
});
24322435

@@ -2935,9 +2938,11 @@ apiDescribe.skipClassic('Pipelines', persistence => {
29352938
snapshot,
29362939
{
29372940
title: "The Hitchhiker's Guide to the Galaxy",
2938-
'awards.hugo': true
2941+
awards: {
2942+
hugo: true
2943+
}
29392944
},
2940-
{ title: 'Dune', 'awards.hugo': true }
2945+
{ title: 'Dune', awards: { hugo: true } }
29412946
);
29422947
});
29432948

@@ -2950,7 +2955,7 @@ apiDescribe.skipClassic('Pipelines', persistence => {
29502955
.replaceWith(
29512956
map({
29522957
title: 'foo',
2953-
nested: {
2958+
nestedField: {
29542959
level: {
29552960
'1': 'bar'
29562961
},
@@ -2962,13 +2967,17 @@ apiDescribe.skipClassic('Pipelines', persistence => {
29622967
)
29632968
.select(
29642969
'title',
2965-
field('nested.level.1'),
2966-
mapGet('nested', 'level.1').mapGet('level.2').as('nested')
2970+
field('nestedField.level.1'),
2971+
mapGet('nestedField', 'level.1').mapGet('level.2').as('nested')
29672972
)
29682973
);
29692974
expectResults(snapshot, {
29702975
title: 'foo',
2971-
'nested.level.`1`': 'bar',
2976+
nestedField: {
2977+
level: {
2978+
'1': 'bar'
2979+
}
2980+
},
29722981
nested: 'baz'
29732982
});
29742983
});
@@ -4278,17 +4287,17 @@ apiDescribe.skipClassic('Pipelines', persistence => {
42784287
})
42794288
)
42804289
.select(
4281-
field('foo').round(0).as('0'),
4282-
round('foo', 1).as('1'),
4283-
round('foo', constant(2)).as('2'),
4284-
round(field('foo'), 4).as('4')
4290+
field('foo').round(0).as('roundedTo0'),
4291+
round('foo', 1).as('roundedTo1'),
4292+
round('foo', constant(2)).as('roundedTo2'),
4293+
round(field('foo'), 4).as('roundedTo4')
42854294
)
42864295
);
42874296
expectResults(snapshot, {
4288-
'0': 4,
4289-
'1': 4.1,
4290-
'2': 4.12,
4291-
'4': 4.1235
4297+
roundedTo0: 4,
4298+
roundedTo1: 4.1,
4299+
roundedTo2: 4.12,
4300+
roundedTo4: 4.1235
42924301
});
42934302
});
42944303

@@ -4332,17 +4341,17 @@ apiDescribe.skipClassic('Pipelines', persistence => {
43324341
})
43334342
)
43344343
.select(
4335-
field('foo').trunc(0).as('0'),
4336-
trunc('foo', 1).as('1'),
4337-
trunc('foo', constant(2)).as('2'),
4338-
trunc(field('foo'), 4).as('4')
4344+
field('foo').trunc(0).as('truncatedTo0'),
4345+
trunc('foo', 1).as('truncatedTo1'),
4346+
trunc('foo', constant(2)).as('truncatedTo2'),
4347+
trunc(field('foo'), 4).as('truncatedTo4')
43394348
)
43404349
);
43414350
expectResults(snapshot, {
4342-
'0': 4,
4343-
'1': 4.1,
4344-
'2': 4.12,
4345-
'4': 4.1234
4351+
truncatedTo0: 4,
4352+
truncatedTo1: 4.1,
4353+
truncatedTo2: 4.12,
4354+
truncatedTo4: 4.1234
43464355
});
43474356
});
43484357

@@ -4966,15 +4975,15 @@ apiDescribe.skipClassic('Pipelines', persistence => {
49664975
constant(1).as('pos1')
49674976
)
49684977
.select(
4969-
abs('neg10').as('10'),
4970-
abs(field('neg22')).as('22'),
4971-
field('pos1').as('1')
4978+
abs('neg10').as('abs10'),
4979+
abs(field('neg22')).as('abs22'),
4980+
field('pos1').as('abs1')
49724981
)
49734982
);
49744983
expectResults(snapshot, {
4975-
'10': 10,
4976-
'22': 22.22,
4977-
'1': 1
4984+
'abs10': 10,
4985+
'abs22': 22.22,
4986+
'abs1': 1
49784987
});
49794988
});
49804989

0 commit comments

Comments
 (0)