diff --git a/src/targets/createUserPool.test.ts b/src/targets/createUserPool.test.ts index 33249140..f0d742ae 100644 --- a/src/targets/createUserPool.test.ts +++ b/src/targets/createUserPool.test.ts @@ -91,6 +91,50 @@ describe("CreateUserPool target", () => { }); }); + it("creates a new user pool with a custom developer-only attribute", async () => { + const createdUserPool = TDB.userPool(); + mockCognitoService.createUserPool.mockResolvedValue(createdUserPool); + + const result = await createUserPool(TestContext, { + PoolName: "test-pool", + Schema: [ + { + Name: "my_attribute", + AttributeDataType: "String", + DeveloperOnlyAttribute: true, + }, + ], + }); + + expect(mockCognitoService.createUserPool).toHaveBeenCalledWith( + TestContext, + { + Arn: expect.stringMatching( + /^arn:aws:cognito-idp:local:local:userpool\/local_[\w\d]{8}$/ + ), + CreationDate: originalDate, + Id: expect.stringMatching(/^local_[\w\d]{8}$/), + LastModifiedDate: originalDate, + Name: "test-pool", + SchemaAttributes: [ + ...(USER_POOL_AWS_DEFAULTS.SchemaAttributes ?? []), + { + Name: "dev:custom:my_attribute", + AttributeDataType: "String", + DeveloperOnlyAttribute: true, + Mutable: true, + Required: false, + StringAttributeConstraints: {}, + }, + ], + } + ); + + expect(result).toEqual({ + UserPool: createdUserPool, + }); + }); + it("creates a new user pool with an overridden attribute", async () => { const createdUserPool = TDB.userPool(); mockCognitoService.createUserPool.mockResolvedValue(createdUserPool); diff --git a/src/targets/createUserPool.ts b/src/targets/createUserPool.ts index f774a427..f6ebe13d 100644 --- a/src/targets/createUserPool.ts +++ b/src/targets/createUserPool.ts @@ -56,7 +56,7 @@ const createSchemaAttributes = ( const type = attr.AttributeDataType ?? "String"; return { - Name: `custom:${attr.Name}`, + Name: `${attr.DeveloperOnlyAttribute ? "dev:" : ""}custom:${attr.Name}`, AttributeDataType: type, DeveloperOnlyAttribute: attr.DeveloperOnlyAttribute ?? false, Mutable: attr.Mutable ?? true,