Skip to content

Commit

Permalink
Add test for oneof conversion (google#1893)
Browse files Browse the repository at this point in the history
Co-authored-by: Roberto Fontanarosa <[email protected]>
  • Loading branch information
gino-m and rfontanarosa authored Jul 2, 2024
1 parent 598aed7 commit 8d1ac77
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
21 changes: 19 additions & 2 deletions lib/src/proto-to-firestore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import {
$color,
$index,
$dtq$type,
$required,
$level,
$textQuestion,
} from './testing/proto-field-aliases';

const {Job, Role, Style, Survey, Task, LinearRing, Coordinates} =
Expand All @@ -41,7 +44,7 @@ describe('toDocumentData()', () => {
}),
expected: {
[$title]: 'Survey name',
[$description]: 'Survey desc',
[$description]: 'Survey desc',
},
},
{
Expand Down Expand Up @@ -101,7 +104,7 @@ describe('toDocumentData()', () => {
type: Task.DateTimeQuestion.Type.TYPE_UNSPECIFIED,
}),
expected: {
[$dtq$type]: 0 // UNSPECIFIED
[$dtq$type]: 0, // UNSPECIFIED
},
},
{
Expand All @@ -121,6 +124,20 @@ describe('toDocumentData()', () => {
],
},
},
{
desc: 'converts oneof',
input: new Task({
textQuestion: new Task.TextQuestion({
type: Task.TextQuestion.Type.SHORT_TEXT,
}),
}),
expected: {
[$index]: 0,
[$required]: false,
[$level]: 0,
[$textQuestion]: {'1': 1},
},
},
].forEach(({desc, input, expected}) =>
it(desc, () => {
const output = toDocumentData(input);
Expand Down
4 changes: 3 additions & 1 deletion lib/src/testing/proto-field-aliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ export const [$latitude, $longitude] = [1, 2];
export const [$index, $style] = [2, 4];
// Style fields:
export const [$color] = [1];
// Task fields:
export const [$required, $level, $textQuestion] = [4, 5, 7];
// DateTimeQuestion:
export const [$dtq$type] = [1];
export const [$dtq$type] = [1];

0 comments on commit 8d1ac77

Please sign in to comment.