Skip to content

Commit 20c182b

Browse files
committed
Partial tests
1 parent 8bc67ed commit 20c182b

File tree

3 files changed

+108
-1
lines changed

3 files changed

+108
-1
lines changed

packages/microapps-datalib/src/models/application.spec.ts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ describe('application records', () => {
3333

3434
await application.Save(dbManager);
3535

36+
//
37+
// Single item key
38+
//
3639
{
3740
const { Item } = await dbManager.ddbDocClient.get({
3841
TableName: TEST_TABLE_NAME,
@@ -45,6 +48,9 @@ describe('application records', () => {
4548
expect(Item?.DisplayName).toBe('Dog');
4649
}
4750

51+
//
52+
// List key
53+
//
4854
{
4955
const { Item } = await dbManager.ddbDocClient.get({
5056
TableName: TEST_TABLE_NAME,
@@ -59,6 +65,96 @@ describe('application records', () => {
5965
}
6066
});
6167

68+
it.only('saving an application with two extra appnames should create four records', async () => {
69+
const application = new Application();
70+
application.AppName = 'Cat';
71+
application.DisplayName = 'Dog';
72+
application.ExtraAppNames = ['Kitty', 'Kitten'];
73+
74+
await application.Save(dbManager);
75+
76+
//
77+
// Single item key
78+
//
79+
80+
// Get the primary app record
81+
{
82+
const { Item } = await dbManager.ddbDocClient.get({
83+
TableName: TEST_TABLE_NAME,
84+
Key: { PK: 'appname#cat', SK: 'application' },
85+
});
86+
expect(Item).toBeDefined();
87+
expect(Item?.PK).toBe('appname#cat');
88+
expect(Item?.SK).toBe('application');
89+
expect(Item?.AppName).toBe('cat');
90+
expect(Item?.DisplayName).toBe('Dog');
91+
}
92+
93+
// Get the secondary app records
94+
{
95+
const { Item } = await dbManager.ddbDocClient.get({
96+
TableName: TEST_TABLE_NAME,
97+
Key: { PK: 'appname#kitty', SK: 'application' },
98+
});
99+
expect(Item).toBeDefined();
100+
expect(Item?.PK).toBe('appname#kitty');
101+
expect(Item?.SK).toBe('application');
102+
expect(Item?.AppName).toBe('cat');
103+
expect(Item?.DisplayName).toBe('Dog');
104+
}
105+
{
106+
const { Item } = await dbManager.ddbDocClient.get({
107+
TableName: TEST_TABLE_NAME,
108+
Key: { PK: 'appname#kitten', SK: 'application' },
109+
});
110+
expect(Item).toBeDefined();
111+
expect(Item?.PK).toBe('appname#kitten');
112+
expect(Item?.SK).toBe('application');
113+
expect(Item?.AppName).toBe('cat');
114+
expect(Item?.DisplayName).toBe('Dog');
115+
}
116+
117+
//
118+
// List key
119+
//
120+
{
121+
const { Item } = await dbManager.ddbDocClient.get({
122+
TableName: TEST_TABLE_NAME,
123+
Key: { PK: 'applications', SK: 'appname#cat' },
124+
// ProjectionExpression: 'PK,SK,AppName,DisplayName',
125+
});
126+
expect(Item).toBeDefined();
127+
expect(Item?.PK).toBe('applications');
128+
expect(Item?.SK).toBe('appname#cat');
129+
expect(Item?.AppName).toBe('cat');
130+
expect(Item?.DisplayName).toBe('Dog');
131+
}
132+
{
133+
const { Item } = await dbManager.ddbDocClient.get({
134+
TableName: TEST_TABLE_NAME,
135+
Key: { PK: 'applications', SK: 'appname#keey' },
136+
// ProjectionExpression: 'PK,SK,AppName,DisplayName',
137+
});
138+
expect(Item).toBeDefined();
139+
expect(Item?.PK).toBe('applications');
140+
expect(Item?.SK).toBe('appname#kitty');
141+
expect(Item?.AppName).toBe('cat');
142+
expect(Item?.DisplayName).toBe('Dog');
143+
}
144+
{
145+
const { Item } = await dbManager.ddbDocClient.get({
146+
TableName: TEST_TABLE_NAME,
147+
Key: { PK: 'applications', SK: 'appname#kitten' },
148+
// ProjectionExpression: 'PK,SK,AppName,DisplayName',
149+
});
150+
expect(Item).toBeDefined();
151+
expect(Item?.PK).toBe('applications');
152+
expect(Item?.SK).toBe('appname#kitten');
153+
expect(Item?.AppName).toBe('cat');
154+
expect(Item?.DisplayName).toBe('Dog');
155+
}
156+
});
157+
62158
it('load function should load records', async () => {
63159
let application = new Application();
64160
application.AppName = 'App1';

packages/microapps-datalib/src/models/application.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface IApplicationRecord {
2121
SK: string;
2222
AppName: string;
2323
DisplayName: string;
24+
ExtraAppNames: string[];
2425
}
2526

2627
export class Application implements IApplicationRecord {
@@ -96,6 +97,7 @@ export class Application implements IApplicationRecord {
9697
private _keyBy: SaveBy;
9798
private _appName: string | undefined;
9899
private _displayName: string | undefined;
100+
private _extraAppNames: string[] | undefined;
99101

100102
public constructor(init?: Partial<IApplicationRecord>) {
101103
Object.assign(this, init);
@@ -108,6 +110,7 @@ export class Application implements IApplicationRecord {
108110
SK: this.SK,
109111
AppName: this.AppName,
110112
DisplayName: this.DisplayName,
113+
ExtraAppNames: this._extraAppNames ?? [],
111114
};
112115
}
113116

@@ -170,4 +173,11 @@ export class Application implements IApplicationRecord {
170173
public set DisplayName(value: string) {
171174
this._displayName = value;
172175
}
176+
177+
public get ExtraAppNames(): string[] {
178+
return this._extraAppNames as string[];
179+
}
180+
public set ExtraAppNames(value: string[]) {
181+
this._extraAppNames = value;
182+
}
173183
}

packages/microapps-edge-to-origin/src/index.route.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,15 @@ describe('edge-to-origin - routing - without prefix', () => {
291291
expect(requestResponse?.origin?.custom?.domainName).toBe('abc123.lambda-url.us-east-1.on.aws');
292292
});
293293

294-
it('should route `direct` app request with *additional* appName to origin for actual appName', async () => {
294+
it.only('should route `direct` app request with *additional* appName to origin for actual appName', async () => {
295295
theConfig.replaceHostHeader = true;
296296
const AppName = 'BatDirect';
297297
const SemVer = '1.2.1-beta.1';
298298
const AppNameExtraRoute = 'BatDirectExtraRoute';
299299

300300
const app = new Application({
301301
AppName,
302+
ExtraAppNames: [AppNameExtraRoute],
302303
DisplayName: 'Direct Bat App',
303304
});
304305
await app.Save(dbManager);

0 commit comments

Comments
 (0)