Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/agentPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ export class AgentPublisher {
* @returns Promise<PublishAgent> The publish response
*/
public async publishAgentJson(): Promise<PublishAgent> {
// store the access token so we can restore it afterwards
const accessToken = this.connection.accessToken;
// Ensure we use the correct connection for this API call
await useNamedUserJwt(this.connection);

Expand All @@ -105,8 +103,9 @@ export class AgentPublisher {
const url = botId ? `${this.API_URL}/${botId}/versions` : this.API_URL;
const response = await this.maybeMock.request<PublishAgentJsonResponse>('POST', url, body, this.API_HEADERS);

// restore the access token
this.connection.accessToken = accessToken;
// stop using named user jwt access token
delete this.connection.accessToken;
await this.connection.refreshAuth();

if (response.botId && response.botVersionId) {
// we've published the AgentJson, now we need to:
Expand Down
9 changes: 9 additions & 0 deletions test/agentPublisher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ describe('AgentPublisher', () => {
// Mock useNamedUserJwt to return the connection without making HTTP calls
$$.SANDBOX.stub(utils, 'useNamedUserJwt').resolves(connection);

// Mock connection.refreshAuth to avoid making HTTP calls during auth refresh
$$.SANDBOX.stub(connection, 'refreshAuth').resolves();

// Mock the private methods
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const retrieveAgentMetadataStub = $$.SANDBOX.stub(publisher as any, 'retrieveAgentMetadata').resolves();
Expand All @@ -131,6 +134,9 @@ describe('AgentPublisher', () => {
// Mock useNamedUserJwt to return the connection without making HTTP calls
$$.SANDBOX.stub(utils, 'useNamedUserJwt').resolves(connection);

// Mock connection.refreshAuth to avoid making HTTP calls during auth refresh
$$.SANDBOX.stub(connection, 'refreshAuth').resolves();

// Mock connection.singleRecordQuery to return undefined (no existing bot)
$$.SANDBOX.stub(connection, 'singleRecordQuery')
.withArgs("SELECT Id FROM BotDefinition WHERE DeveloperName='test_agent'")
Expand All @@ -157,6 +163,9 @@ describe('AgentPublisher', () => {
// Mock useNamedUserJwt to return the connection without making HTTP calls
$$.SANDBOX.stub(utils, 'useNamedUserJwt').resolves(connection);

// Mock connection.refreshAuth to avoid making HTTP calls during auth refresh
$$.SANDBOX.stub(connection, 'refreshAuth').resolves();

try {
await publisher.publishAgentJson();
expect.fail('Expected error was not thrown');
Expand Down
2 changes: 2 additions & 0 deletions test/agents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ describe('Agents', () => {

// Mock useNamedUserJwt to return the connection without making HTTP calls
$$.SANDBOX.stub(utils, 'useNamedUserJwt').resolves(connection);
// Mock connection.refreshAuth to avoid making HTTP calls during auth refresh
$$.SANDBOX.stub(connection, 'refreshAuth').resolves();

try {
await Agent.publishAgentJson(connection, sfProject, agentJson);
Expand Down
Loading