|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the SwiftAWSLambdaRuntime open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2017-2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors |
| 6 | +// Licensed under Apache License v2.0 |
| 7 | +// |
| 8 | +// See LICENSE.txt for license information |
| 9 | +// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors |
| 10 | +// |
| 11 | +// SPDX-License-Identifier: Apache-2.0 |
| 12 | +// |
| 13 | +//===----------------------------------------------------------------------===// |
| 14 | + |
| 15 | +@testable import AWSLambdaEvents |
| 16 | +import HTTPTypes |
| 17 | +import XCTest |
| 18 | + |
| 19 | +class BedrockAgentTests: XCTestCase { |
| 20 | + static let eventBody = |
| 21 | + """ |
| 22 | + { |
| 23 | + "messageVersion": "1.0", |
| 24 | + "agent": { |
| 25 | + "alias": "AGENT_ID", |
| 26 | + "name": "StockQuoteAgent", |
| 27 | + "version": "DRAFT", |
| 28 | + "id": "PR3AHNYEAA" |
| 29 | + }, |
| 30 | + "sessionId": "486652066693565", |
| 31 | + "sessionAttributes": {}, |
| 32 | + "promptSessionAttributes": {}, |
| 33 | + "inputText": "what the price of amazon stock ?", |
| 34 | + "apiPath": "/stocks/{symbol}", |
| 35 | + "actionGroup": "StockQuoteService", |
| 36 | + "httpMethod": "GET", |
| 37 | + "parameters": [ |
| 38 | + { |
| 39 | + "name": "symbol", |
| 40 | + "type": "string", |
| 41 | + "value": "AMZN" |
| 42 | + } |
| 43 | + ], |
| 44 | + "requestBody": { |
| 45 | + "content": { |
| 46 | + "application/text": { |
| 47 | + "properties": [ |
| 48 | + { |
| 49 | + "name": "symbol", |
| 50 | + "type": "string", |
| 51 | + "value": "AMZN" |
| 52 | + } |
| 53 | + ] |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + """ |
| 59 | + |
| 60 | + func testSimpleEventFromJSON() throws { |
| 61 | + let data = BedrockAgentTests.eventBody.data(using: .utf8)! |
| 62 | + var event: BedrockAgentRequest? |
| 63 | + XCTAssertNoThrow(event = try JSONDecoder().decode(BedrockAgentRequest.self, from: data)) |
| 64 | + |
| 65 | + XCTAssertEqual(event?.messageVersion, "1.0") |
| 66 | + |
| 67 | + XCTAssertEqual(event?.agent?.alias, "AGENT_ID") |
| 68 | + XCTAssertEqual(event?.agent?.name, "StockQuoteAgent") |
| 69 | + XCTAssertEqual(event?.agent?.version, "DRAFT") |
| 70 | + XCTAssertEqual(event?.agent?.id, "PR3AHNYEAA") |
| 71 | + |
| 72 | + XCTAssertEqual(event?.sessionId, "486652066693565") |
| 73 | + XCTAssertEqual(event?.inputText, "what the price of amazon stock ?") |
| 74 | + XCTAssertEqual(event?.apiPath, "/stocks/{symbol}") |
| 75 | + XCTAssertEqual(event?.actionGroup, "StockQuoteService") |
| 76 | + XCTAssertEqual(event?.httpMethod, .get) |
| 77 | + |
| 78 | + XCTAssertTrue(event?.parameters?.count == 1) |
| 79 | + XCTAssertEqual(event?.parameters?[0].name, "symbol") |
| 80 | + XCTAssertEqual(event?.parameters?[0].type, "string") |
| 81 | + XCTAssertEqual(event?.parameters?[0].value, "AMZN") |
| 82 | + |
| 83 | + let body = try XCTUnwrap(event?.requestBody?.content) |
| 84 | + let content = try XCTUnwrap(body["application/text"]) |
| 85 | + XCTAssertTrue(content.properties.count == 1) |
| 86 | + XCTAssertEqual(content.properties[0].name, "symbol") |
| 87 | + XCTAssertEqual(content.properties[0].type, "string") |
| 88 | + XCTAssertEqual(content.properties[0].value, "AMZN") |
| 89 | + } |
| 90 | +} |
0 commit comments