Skip to content

Commit

Permalink
chore(websockets): fix tests (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chriscbr authored Mar 22, 2024
1 parent c9d6238 commit 4a1f124
Show file tree
Hide file tree
Showing 6 changed files with 7,360 additions and 3,571 deletions.
3 changes: 3 additions & 0 deletions websockets/inflight/websocket.aws.extern.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default interface extern {
_postToConnection: (endpointUrl: string, connectionId: string, message: string) => Promise<void>,
}
20 changes: 10 additions & 10 deletions websockets/lib.test.w
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
bring cloud;
bring ex;
bring dynamodb;
bring util;
bring "./lib.w" as websockets;

let tb = new ex.DynamodbTable(
let tb = new dynamodb.Table(
name: "WebSocketTable",
hashKey: "connectionId",
attributeDefinitions: {
"connectionId": "S",
},
attributes: [{
name: "connectionId", type: "S",
}],
);

let wb = new websockets.WebSocket(name: "MyWebSocket") as "my-websocket";

wb.onConnect(inflight(id: str): void => {
tb.putItem({
item: {
tb.put({
Item: {
"connectionId": id
}
});
});

wb.onDisconnect(inflight(id: str): void => {
tb.deleteItem({
key: {
tb.delete({
Key: {
"connectionId": id
}
});
});

wb.onMessage(inflight (id: str, body: str): void => {
let connections = tb.scan();
for item in connections.items {
for item in connections.Items {
wb.sendMessage(str.fromJson(item.get("connectionId")), body);
}
});
Expand Down
Loading

0 comments on commit 4a1f124

Please sign in to comment.