Skip to content

Commit

Permalink
fix: reverting schema change for model based hasMany integ test
Browse files Browse the repository at this point in the history
  • Loading branch information
bombguy committed Dec 1, 2022
1 parent e4e8583 commit 95e8f14
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 277 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ describe('CreateForms', () => {
expect(record.stringArray[0]).to.equal('String1');
expect(record.HasOneUser.firstName).to.equal('John');
expect(record.HasManyStudents?.[0].name).to.equal('David');
expect(record.HasManyStudents?.[0].allSupportedFormFieldsID).to.equal(record.id);
expect(record.HasManyStudents?.[1].name).to.equal('Sarah');
expect(record.HasManyStudents?.[1].allSupportedFormFieldsID).to.equal(record.id);
expect(record.BelongsToOwner.name).to.equal('John');
expect(record.ManyToManyTags[0].label).to.equal('Blue');
expect(record.ManyToManyTags[1].label).to.equal('Green');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ describe('UpdateForms', () => {
expect(record.ManyToManyTags[1].label).to.equal('Orange');
expect(record.BelongsToOwner.name).to.equal('George');
expect(record.HasManyStudents[0].name).to.equal('Matthew');
expect(record.HasManyStudents[0].allSupportedFormFieldsID).to.equal(record.id);
expect(record.HasManyStudents[1].name).to.equal('Sarah');
expect(record.HasManyStudents[1].allSupportedFormFieldsID).to.equal(record.id);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,7 @@ import {
CustomFormCreateNestedJson,
} from './ui-components'; // eslint-disable-line import/extensions, max-len

import {
AllSupportedFormFields,
Owner,
User,
Tag,
LazyTag,
Student,
LazyAllSupportedFormFieldsStudent,
LazyAllSupportedFormFieldsTag,
LazyStudent,
} from './models';
import { AllSupportedFormFields, Owner, User, Tag, LazyTag, Student, LazyAllSupportedFormFieldsTag } from './models';
import { getModelsFromJoinTableRecords } from './test-utils';

const initializeTestData = async (): Promise<void> => {
Expand Down Expand Up @@ -122,19 +112,13 @@ export default function CreateFormTests() {
);
ManyToManyTags.sort((a, b) => a.label?.localeCompare(b.label as string) as number);

const HasManyStudents = await getModelsFromJoinTableRecords<LazyStudent, LazyAllSupportedFormFieldsStudent>(
record,
'HasManyStudents',
'student',
);

setDataStoreFormCreateAllSupportedFormFieldsRecord(
JSON.stringify({
...record,
HasOneUser: await record.HasOneUser,
BelongsToOwner: await record.BelongsToOwner,
HasManyStudents: await record.HasManyStudents?.toArray(),
ManyToManyTags,
HasManyStudents,
}),
);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ import {
Tag,
Student,
LazyTag,
LazyStudent,
AllSupportedFormFields,
AllSupportedFormFieldsTag,
AllSupportedFormFieldsStudent,
LazyAllSupportedFormFieldsTag,
LazyAllSupportedFormFieldsStudent,
} from './models';
import { getModelsFromJoinTableRecords } from './test-utils';

Expand All @@ -47,8 +44,6 @@ const initializeTestData = async (): Promise<void> => {
await DataStore.save(new Tag({ label: 'Green' }));
await DataStore.save(new Tag({ label: 'Orange' }));
await DataStore.save(new Student({ name: 'Matthew' }));
await DataStore.save(new Student({ name: 'Jessica' }));
await DataStore.save(new Student({ name: 'David' }));
await DataStore.save(new Student({ name: 'Sarah' }));
};

Expand All @@ -60,9 +55,6 @@ const initializeAllSupportedFormFieldsTestData = async ({
const connectedUser = (await DataStore.query(User, (u) => u.firstName.eq('John')))[0];
const connectedOwner = (await DataStore.query(Owner, (owner) => owner.name.eq('John')))[0];
const connectedTags = await DataStore.query(Tag, (tag) => tag.or((t) => [t.label.eq('Red'), t.label.eq('Blue')]));
const connectedStudent = await DataStore.query(Student, (tag) =>
tag.or((t) => [t.name.eq('David'), t.name.eq('Jessica')]),
);
const createdRecord = await DataStore.save(
new AllSupportedFormFields({
string: 'My string',
Expand All @@ -86,6 +78,9 @@ const initializeAllSupportedFormFieldsTestData = async ({
}),
);

await DataStore.save(new Student({ name: 'David', allSupportedFormFieldsID: createdRecord.id }));
await DataStore.save(new Student({ name: 'Jessica', allSupportedFormFieldsID: createdRecord.id }));

// connect tags through join table
await Promise.all(
connectedTags.reduce((promises: AsyncItem<LazyTag>[], tag) => {
Expand All @@ -101,20 +96,6 @@ const initializeAllSupportedFormFieldsTestData = async ({
}, []),
);

await Promise.all(
connectedStudent.reduce((promises: AsyncItem<LazyStudent>[], student) => {
promises.push(
DataStore.save(
new AllSupportedFormFieldsStudent({
allSupportedFormFields: createdRecord,
student,
}),
),
);
return promises;
}, []),
);

setAllSupportedFormFieldsRecordId((prevId) => {
if (!prevId) {
return createdRecord.id;
Expand Down Expand Up @@ -169,19 +150,13 @@ export default function UpdateFormTests() {
);
ManyToManyTags.sort((a, b) => a.label?.localeCompare(b.label as string) as number);

const HasManyStudents = await getModelsFromJoinTableRecords<LazyStudent, LazyAllSupportedFormFieldsStudent>(
record,
'HasManyStudents',
'student',
);

setDataStoreFormUpdateAllSupportedFormFieldsRecord(
JSON.stringify({
...record,
HasOneUser: await record.HasOneUser,
BelongsToOwner: await record.BelongsToOwner,
HasManyStudents: await record.HasManyStudents?.toArray(),
ManyToManyTags,
HasManyStudents,
}),
);
}}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const {
Class,
Tag,
AllSupportedFormFieldsTag,
AllSupportedFormFieldsStudent,
Owner,
Student,
AllSupportedFormFields,
Expand All @@ -52,7 +51,6 @@ export {
Class,
Tag,
AllSupportedFormFieldsTag,
AllSupportedFormFieldsStudent,
Owner,
Student,
AllSupportedFormFields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,82 +472,6 @@ export const schema = {
},
],
},
AllSupportedFormFieldsStudent: {
name: 'AllSupportedFormFieldsStudent',
fields: {
id: {
name: 'id',
isArray: false,
type: 'ID',
isRequired: true,
attributes: [],
},
student: {
name: 'student',
isArray: false,
type: {
model: 'Student',
},
isRequired: true,
attributes: [],
association: {
connectionType: 'BELONGS_TO',
targetName: 'studentID',
},
},
allSupportedFormFields: {
name: 'allSupportedFormFields',
isArray: false,
type: {
model: 'AllSupportedFormFields',
},
isRequired: true,
attributes: [],
association: {
connectionType: 'BELONGS_TO',
targetName: 'allSupportedFormFieldsID',
},
},
createdAt: {
name: 'createdAt',
isArray: false,
type: 'AWSDateTime',
isRequired: false,
attributes: [],
isReadOnly: true,
},
updatedAt: {
name: 'updatedAt',
isArray: false,
type: 'AWSDateTime',
isRequired: false,
attributes: [],
isReadOnly: true,
},
},
syncable: true,
pluralName: 'AllSupportedFormFieldsStudents',
attributes: [
{
type: 'model',
properties: {},
},
{
type: 'key',
properties: {
name: 'byStudent',
fields: ['studentID'],
},
},
{
type: 'key',
properties: {
name: 'byAllSupportedFormFields',
fields: ['allSupportedFormFieldsID'],
},
},
],
},
Owner: {
name: 'Owner',
fields: {
Expand Down Expand Up @@ -640,19 +564,12 @@ export const schema = {
isRequired: false,
attributes: [],
},
AllSupportedFormFields: {
name: 'AllSupportedFormFields',
isArray: true,
type: {
model: 'AllSupportedFormFieldsStudent',
},
isRequired: false,
allSupportedFormFieldsID: {
name: 'allSupportedFormFieldsID',
isArray: false,
type: 'ID',
isRequired: true,
attributes: [],
isArrayNullable: true,
association: {
connectionType: 'HAS_MANY',
associatedWith: 'student',
},
},
createdAt: {
name: 'createdAt',
Expand Down Expand Up @@ -862,14 +779,14 @@ export const schema = {
name: 'HasManyStudents',
isArray: true,
type: {
model: 'AllSupportedFormFieldsStudent',
model: 'Student',
},
isRequired: false,
attributes: [],
isArrayNullable: true,
association: {
connectionType: 'HAS_MANY',
associatedWith: 'allSupportedFormFields',
associatedWith: 'allSupportedFormFieldsID',
},
},
ManyToManyTags: {
Expand Down

0 comments on commit 95e8f14

Please sign in to comment.