Skip to content

Commit

Permalink
Add TurnStateProperty tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Corina Gum committed Apr 26, 2024
1 parent fcff618 commit 793332d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 8 deletions.
16 changes: 8 additions & 8 deletions js/packages/teams-ai/src/TeamsAttachmentDownloader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('TeamsAttachmentDownloader', () => {
attachments: [attachment]
} as Partial<Activity>;
const [context, state] = await createTestTurnContextAndState(adapter, activity);
// const state = new TurnState();

const result = await downloader.downloadFiles(context, state);

assert.equal(postStub.calledOnce, true);
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('TeamsAttachmentDownloader', () => {
attachments: [attachment]
} as Partial<Activity>;
const [context, state] = await createTestTurnContextAndState(adapter, activity);
// const state = new TurnState();

const result = await downloader.downloadFiles(context, state);

assert.equal(postStub.calledOnce, true);
Expand Down Expand Up @@ -117,7 +117,7 @@ describe('TeamsAttachmentDownloader', () => {
attachments: [attachment]
} as Partial<Activity>;
const [context, state] = await createTestTurnContextAndState(adapter, activity);
// const state = new TurnState();

const result = await downloader.downloadFiles(context, state);

assert.equal(postStub.calledOnce, true);
Expand All @@ -144,7 +144,7 @@ describe('TeamsAttachmentDownloader', () => {
attachments: [attachment]
} as Partial<Activity>;
const [context, state] = await createTestTurnContextAndState(adapter, activity);
// const state = new TurnState();

const result = await downloader.downloadFiles(context, state);

assert.deepEqual(result, [
Expand All @@ -163,7 +163,7 @@ describe('TeamsAttachmentDownloader', () => {
attachments: []
} as Partial<Activity>;
const [context, state] = await createTestTurnContextAndState(adapter, activity);
// const state = new TurnState();

const result = await downloader.downloadFiles(context, state);

assert.deepEqual(result, []);
Expand Down Expand Up @@ -211,7 +211,7 @@ describe('TeamsAttachmentDownloader', () => {
});

const [context, state] = await createTestTurnContextAndState(adapter, activity);
// const state = new TurnState();

const result = await downloader.downloadFiles(context, state);

assert.equal(postStub.calledOnce, true);
Expand Down Expand Up @@ -256,7 +256,7 @@ describe('TeamsAttachmentDownloader', () => {
});

const [context, state] = await createTestTurnContextAndState(adapter, activity);
// const state = new TurnState();

const result = await downloader.downloadFiles(context, state);

assert.equal(postStub.calledOnce, true);
Expand Down Expand Up @@ -300,7 +300,7 @@ describe('TeamsAttachmentDownloader', () => {
});

const [context, state] = await createTestTurnContextAndState(adapter, activity);
// const state = new TurnState();

const result = await downloader.downloadFiles(context, state);

assert.equal(postStub.calledOnce, true);
Expand Down
51 changes: 51 additions & 0 deletions js/packages/teams-ai/src/TurnStateProperty.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { strict as assert } from 'assert';
import { TurnState } from './TurnState';
import { TurnStateProperty } from './TurnStateProperty';
import { createTestTurnContextAndState } from './internals/testing/TestUtilities';
import { TestAdapter } from 'botbuilder';

describe('TurnStateProperty', () => {
it('should throw an error when TurnState is missing state scope named scope', () => {
const state = new TurnState();
const scopeName = 'scope';
const propertyName = 'propertyName';

assert.throws(() => new TurnStateProperty(state, scopeName, propertyName)),
`TurnStateProperty: TurnState missing state scope named "propertyName".`;
});

it('should set the turn state property', async () => {
const adapter = new TestAdapter();
const [context, state] = await createTestTurnContextAndState(adapter, {
type: 'message',
from: {
id: 'test',
name: 'test'
}
});
const propertyName = 'tempStateProperty';
const turnStateProperty = new TurnStateProperty(state, 'temp', propertyName);

await turnStateProperty.set(context, 'someValue');
const value = await turnStateProperty.get(context);
assert.equal(value, 'someValue');
});

it('should delete the turn state property', async () => {
const adapter = new TestAdapter();
const [context, state] = await createTestTurnContextAndState(adapter, {
type: 'message',
from: {
id: 'test',
name: 'test'
}
});
const propertyName = 'tempStateProperty';
const turnStateProperty = new TurnStateProperty(state, 'temp', propertyName);

await turnStateProperty.set(context, 'someValue');
await turnStateProperty.delete();
const value = await turnStateProperty.get(context);
assert.notEqual(value, 'someValue');
});
});

0 comments on commit 793332d

Please sign in to comment.