Skip to content

Commit

Permalink
Replace done w/ async part 4 (#3427)
Browse files Browse the repository at this point in the history
* convert done to async tests

* no-op formatting fixes

* use assert.rejects

Co-authored-by: Michael Richardson <v-micric@microsoft.com>
Co-authored-by: Josh Gummersall <1235378+joshgummersall@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 24, 2021
1 parent 7f3694f commit 989aca5
Show file tree
Hide file tree
Showing 9 changed files with 779 additions and 737 deletions.
131 changes: 68 additions & 63 deletions libraries/botbuilder-dialogs/tests/attachmentPrompt.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
const { ConversationState, MemoryStorage, TestAdapter } = require('botbuilder-core');
const { AttachmentPrompt, DialogSet, DialogTurnStatus } = require('../');
const { AttachmentPrompt, DialogSet, DialogTurnStatus } = require('../');
const assert = require('assert');

const answerMessage = { text: `here you go`, type: 'message', attachments: [{ contentType: 'test', content: 'test1' }] };
const answerMessage = {
text: `here you go`,
type: 'message',
attachments: [{ contentType: 'test', content: 'test1' }],
};
const invalidMessage = { text: `what?`, type: 'message' };

describe('AttachmentPrompt', function() {
describe('AttachmentPrompt', function () {
this.timeout(5000);

it('should call AttachmentPrompt using dc.prompt().', async function () {
Expand All @@ -24,23 +28,24 @@ describe('AttachmentPrompt', function() {
await convoState.saveChanges(turnContext);
});

// Create new ConversationState with MemoryStorage
// Create new ConversationState with MemoryStorage
const convoState = new ConversationState(new MemoryStorage());
// adapter.use(convoState);

// Create a DialogState property, DialogSet and AttachmentPrompt.
const dialogState = convoState.createProperty('dialogState');
const dialogs = new DialogSet(dialogState);
dialogs.add(new AttachmentPrompt('prompt'));

await adapter.send('Hello')
.assertReply('Please send an attachment.')
.send(answerMessage)
.assertReply('test1')
.startTest();

await adapter
.send('Hello')
.assertReply('Please send an attachment.')
.send(answerMessage)
.assertReply('test1')
.startTest();
});

it('should call AttachmentPrompt with custom validator.', function (done) {
it('should call AttachmentPrompt with custom validator.', async function () {
const adapter = new TestAdapter(async (turnContext) => {
const dc = await dialogs.createContext(turnContext);

Expand All @@ -59,20 +64,22 @@ describe('AttachmentPrompt', function() {

const dialogState = convoState.createProperty('dialogState');
const dialogs = new DialogSet(dialogState);
dialogs.add(new AttachmentPrompt('prompt', async (prompt) => {
assert(prompt);
return prompt.recognized.succeeded;
}));

adapter.send('Hello')
.assertReply('Please send an attachment.')
.send(answerMessage)
.assertReply('test1')
.startTest();
done();
dialogs.add(
new AttachmentPrompt('prompt', async (prompt) => {
assert(prompt);
return prompt.recognized.succeeded;
})
);

await adapter
.send('Hello')
.assertReply('Please send an attachment.')
.send(answerMessage)
.assertReply('test1')
.startTest();
});

it('should send custom retryPrompt.', function (done) {
it('should send custom retryPrompt.', async function () {
const adapter = new TestAdapter(async (turnContext) => {
const dc = await dialogs.createContext(turnContext);

Expand All @@ -91,22 +98,24 @@ describe('AttachmentPrompt', function() {

const dialogState = convoState.createProperty('dialogState');
const dialogs = new DialogSet(dialogState);
dialogs.add(new AttachmentPrompt('prompt', async (prompt) => {
assert(prompt);
return prompt.recognized.succeeded;
}));

adapter.send('Hello')
.assertReply('Please send an attachment.')
.send(invalidMessage)
.assertReply('Please try again.')
.send(answerMessage)
.assertReply('test1')
.startTest();
done();
dialogs.add(
new AttachmentPrompt('prompt', async (prompt) => {
assert(prompt);
return prompt.recognized.succeeded;
})
);

await adapter
.send('Hello')
.assertReply('Please send an attachment.')
.send(invalidMessage)
.assertReply('Please try again.')
.send(answerMessage)
.assertReply('test1')
.startTest();
});

it('should send ignore retryPrompt if validator replies.', function (done) {
it('should send ignore retryPrompt if validator replies.', async function () {
const adapter = new TestAdapter(async (turnContext) => {
const dc = await dialogs.createContext(turnContext);

Expand All @@ -125,26 +134,28 @@ describe('AttachmentPrompt', function() {

const dialogState = convoState.createProperty('dialogState');
const dialogs = new DialogSet(dialogState);
dialogs.add(new AttachmentPrompt('prompt', async (prompt) => {
assert(prompt);

if (!prompt.recognized.succeeded) {
await prompt.context.sendActivity('Bad input.');
}
return prompt.recognized.succeeded;
}));

adapter.send('Hello')
.assertReply('Please send an attachment.')
.send(invalidMessage)
.assertReply('Bad input.')
.send(answerMessage)
.assertReply('test1')
.startTest();
done();
dialogs.add(
new AttachmentPrompt('prompt', async (prompt) => {
assert(prompt);

if (!prompt.recognized.succeeded) {
await prompt.context.sendActivity('Bad input.');
}
return prompt.recognized.succeeded;
})
);

await adapter
.send('Hello')
.assertReply('Please send an attachment.')
.send(invalidMessage)
.assertReply('Bad input.')
.send(answerMessage)
.assertReply('test1')
.startTest();
});

it('should not send any retryPrompt if no prompt is specified.', function (done) {
it('should not send any retryPrompt if no prompt is specified.', async function () {
const adapter = new TestAdapter(async (turnContext) => {
const dc = await dialogs.createContext(turnContext);

Expand All @@ -164,13 +175,7 @@ describe('AttachmentPrompt', function() {
const dialogState = convoState.createProperty('dialogState');
const dialogs = new DialogSet(dialogState);
dialogs.add(new AttachmentPrompt('prompt'));

adapter.send('Hello')
.send('what?')
.send(answerMessage)
.assertReply('test1')
.startTest();
done();
});

await adapter.send('Hello').send('what?').send(answerMessage).assertReply('test1').startTest();
});
});
Loading

0 comments on commit 989aca5

Please sign in to comment.