I'm facing a challenge:
describe("Given a config repository", () => {
let target: ConfigRepository;
beforeEach(() => {
target = InMemoryConfigRepository();
});
test("When creating a new config, Then it is persisted properly", async () => {
const key = "key";
const namespace = "namespace";
const result = await target.upsert({
key,
namespace,
value: "value",
teamId: "teamId",
})();
const configs = await target.findAll()();
expect(result._tag).toEqual("Right");
expect(configs.length).toBe(1);
expect(configs.map((c) => c.key)).toEqual([key]);
});
});
This test can be used to validate any implementation of my interface:
export type ConfigRepository = {
get: <T extends RequiredJsonObject>(
props: ConfigurationProperties<T>
) => TE.TaskEither<DatabaseError | MissingConfigError, ConfigEntity[]>;
findAll(): T.Task<ConfigEntity[]>;
upsert: (
config: UnsavedConfig
) => TE.TaskEither<DatabaseError, ConfigEntity>;
};
The challenge I'm encountering is how to adapt this test for different implementations of the same interface, such as testing a PrismaConfigRepository
. Any suggestions on how I could approach this?