fix(database): fix option-parser include list index (#371)

This commit is contained in:
Junyi 2022-05-11 00:25:43 +08:00 committed by GitHub
parent 565249c05c
commit 45d03d3ca5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -81,6 +81,7 @@ describe('option parser', () => {
], ],
}); });
}); });
test('with sort option', () => { test('with sort option', () => {
let options: any = { let options: any = {
sort: ['id'], sort: ['id'],
@ -182,4 +183,23 @@ describe('option parser', () => {
expect(params['include'][0]['attributes']['exclude']).toContain('id'); expect(params['include'][0]['attributes']['exclude']).toContain('id');
}); });
test('option parser with multiple association', () => {
// fields with association field
const options = {
appends: ['user', 'comments.id', 'tags.id'],
};
const parser = new OptionsParser(options, {
collection: Post,
});
const params = parser.toSequelizeParams();
expect(params.include.length).toBe(3);
expect(params.include[0].association).toBe('user');
expect(params.include[1].association).toBe('comments');
expect(params.include[1].attributes).toEqual(['id']);
expect(params.include[2].association).toBe('tags');
expect(params.include[2].attributes).toEqual(['id']);
});
}); });

View File

@ -230,7 +230,7 @@ export class OptionsParser {
association: appendAssociation, association: appendAssociation,
}); });
existIncludeIndex = 0; existIncludeIndex = queryParams['include'].length - 1;
} }
// end appends // end appends