forked from jagregory/cognito-local
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(config): arrays in config couldn't be overwritten
- Loading branch information
Showing
5 changed files
with
136 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { newMockDataStore } from "../__tests__/mockDataStore"; | ||
import { DefaultConfig, loadConfig } from "./config"; | ||
|
||
describe("loadConfig", () => { | ||
it("returns the default config if no config exists", async () => { | ||
const createDataStore = jest.fn().mockResolvedValue(newMockDataStore()); | ||
|
||
const config = await loadConfig("dir", createDataStore); | ||
|
||
expect(config).toEqual(DefaultConfig); | ||
}); | ||
|
||
it("merges the defaults with any existing config", async () => { | ||
const ds = newMockDataStore(); | ||
const createDataStore = jest.fn().mockResolvedValue(ds); | ||
|
||
ds.getRoot.mockResolvedValue({ | ||
TriggerFunctions: { | ||
CustomMessage: "custom-config", | ||
}, | ||
UserPoolDefaults: { | ||
MFAOptions: "OPTIONAL", | ||
}, | ||
}); | ||
|
||
const config = await loadConfig("dir", createDataStore); | ||
|
||
expect(config).toEqual({ | ||
...DefaultConfig, | ||
TriggerFunctions: { | ||
CustomMessage: "custom-config", | ||
}, | ||
UserPoolDefaults: { | ||
// new field | ||
MFAOptions: "OPTIONAL", | ||
// field from defaults | ||
UsernameAttributes: ["email"], | ||
}, | ||
}); | ||
}); | ||
|
||
it("can unset a property when merging", async () => { | ||
const ds = newMockDataStore(); | ||
const createDataStore = jest.fn().mockResolvedValue(ds); | ||
|
||
ds.getRoot.mockResolvedValue({ | ||
UserPoolDefaults: { | ||
UsernameAttributes: null, | ||
}, | ||
}); | ||
|
||
const config = await loadConfig("dir", createDataStore); | ||
|
||
expect(config).toEqual({ | ||
...DefaultConfig, | ||
UserPoolDefaults: { | ||
UsernameAttributes: null, | ||
}, | ||
}); | ||
}); | ||
|
||
it("overwrites arrays when merging", async () => { | ||
const ds = newMockDataStore(); | ||
const createDataStore = jest.fn().mockResolvedValue(ds); | ||
|
||
ds.getRoot.mockResolvedValue({ | ||
UserPoolDefaults: { | ||
UsernameAttributes: ["phone_number"], | ||
}, | ||
}); | ||
|
||
const config = await loadConfig("dir", createDataStore); | ||
|
||
expect(config).toEqual({ | ||
...DefaultConfig, | ||
UserPoolDefaults: { | ||
UsernameAttributes: ["phone_number"], | ||
}, | ||
}); | ||
}); | ||
|
||
it("can set an arrays to empty when merging", async () => { | ||
const ds = newMockDataStore(); | ||
const createDataStore = jest.fn().mockResolvedValue(ds); | ||
|
||
ds.getRoot.mockResolvedValue({ | ||
UserPoolDefaults: { | ||
UsernameAttributes: [], | ||
}, | ||
}); | ||
|
||
const config = await loadConfig("dir", createDataStore); | ||
|
||
expect(config).toEqual({ | ||
...DefaultConfig, | ||
UserPoolDefaults: { | ||
UsernameAttributes: [], | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters