Skip to content

Commit

Permalink
Correctly build autocompletion responses (#591)
Browse files Browse the repository at this point in the history
* Correctly build autocompletion responses

* Add tests
  • Loading branch information
abitofevrything authored Nov 26, 2023
1 parent d30e9b5 commit 573c9bc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/src/builders/interaction_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class InteractionResponseBuilder extends CreateBuilder<InteractionResponseBuilde

factory InteractionResponseBuilder.autocompleteResult(List<CommandOptionChoiceBuilder<dynamic>> choices) => InteractionResponseBuilder(
type: InteractionCallbackType.applicationCommandAutocompleteResult,
data: {'choices': choices},
data: {'choices': choices.map((e) => e.build()).toList()},
);

factory InteractionResponseBuilder.modal(ModalBuilder modal) => InteractionResponseBuilder(type: InteractionCallbackType.modal, data: modal);
Expand Down
20 changes: 20 additions & 0 deletions test/unit/builders/interaction_response_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:nyxx/nyxx.dart';
import 'package:test/test.dart';

void main() {
group('InteractionResponseBuilder', () {
test('autocompleteResult', () {
expect(
InteractionResponseBuilder.autocompleteResult([CommandOptionChoiceBuilder(name: 'foo', value: 'bar')]).build(),
equals({
'type': 8,
'data': {
'choices': [
{'name': 'foo', 'value': 'bar'},
]
}
}),
);
});
});
}

0 comments on commit 573c9bc

Please sign in to comment.