Skip to content

Commit 450c707

Browse files
committed
make getClientId work with user owned templates
1 parent ae295ed commit 450c707

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lambdas/backend-api/src/__tests__/templates/infra/template-repository.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,22 @@ describe('templateRepository', () => {
15991599
expect(owner).toEqual('template-owner');
16001600
});
16011601

1602+
it('gets clientId when template is user-owned', async () => {
1603+
const { templateRepository, mocks } = setup();
1604+
1605+
mocks.ddbDocClient.on(QueryCommand).resolves({
1606+
Items: [
1607+
{
1608+
owner: 'user-owner',
1609+
},
1610+
],
1611+
});
1612+
1613+
const owner = await templateRepository.getClientId('template-id');
1614+
1615+
expect(owner).toEqual('user-owner');
1616+
});
1617+
16021618
it('errors when owner cannot be found', async () => {
16031619
const { templateRepository, mocks } = setup();
16041620

lambdas/backend-api/src/templates/infra/template-repository.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,9 @@ export class TemplateRepository {
770770
}
771771

772772
private stripClientPrefix(owner: string) {
773-
return owner.slice(this.clientOwnerPrefix.length);
773+
return owner.startsWith(this.clientOwnerPrefix)
774+
? owner.slice(this.clientOwnerPrefix.length)
775+
: owner;
774776
}
775777

776778
private clientOwnerKey(clientId: string) {

0 commit comments

Comments
 (0)