Add data infrastructure modules
This commit is contained in:
1 parent
b4196c6afe
commit
4115646d66
60 files changed
+9642
-2
No files matched your search
@@ -0,0 +1,82 @@
|
||||
import { modelDefinitions } from './index';
|
||||
|
||||
const EXPECTED_MODEL_NAMES = [
|
||||
'account',
|
||||
'riotMatch',
|
||||
'playerMatchFeature',
|
||||
'playerProfile',
|
||||
'analysisJob',
|
||||
'metricBaseline',
|
||||
'recommendation',
|
||||
'championStyleProfile',
|
||||
];
|
||||
|
||||
describe('modelDefinitions registry', () => {
|
||||
it('registers every expected model exactly once', () => {
|
||||
const names = modelDefinitions.map((definition) => definition.name);
|
||||
expect(names.sort()).toEqual([...EXPECTED_MODEL_NAMES].sort());
|
||||
expect(new Set(names).size).toBe(names.length);
|
||||
});
|
||||
|
||||
it('uses unique snake_case singular collection names', () => {
|
||||
const collectionNames = modelDefinitions.map(
|
||||
(definition) => definition.collectionName,
|
||||
);
|
||||
expect(new Set(collectionNames).size).toBe(collectionNames.length);
|
||||
for (const collectionName of collectionNames) {
|
||||
expect(collectionName).toMatch(/^[a-z][a-z_]*[a-z]$/);
|
||||
}
|
||||
});
|
||||
|
||||
it('keeps collectionName in sync with each schema collection option', () => {
|
||||
for (const definition of modelDefinitions) {
|
||||
expect(definition.schema.get('collection')).toBe(
|
||||
definition.collectionName,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it('enables timestamps on every schema', () => {
|
||||
for (const definition of modelDefinitions) {
|
||||
expect(definition.schema.get('timestamps')).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it('declares the unique indexes the pipeline depends on', () => {
|
||||
const uniqueIndexesByModelName: Record<string, Record<string, number>> = {
|
||||
account: { puuid: 1 },
|
||||
riotMatch: { matchId: 1 },
|
||||
playerMatchFeature: { matchId: 1, puuid: 1 },
|
||||
playerProfile: { puuid: 1, queueId: 1 },
|
||||
analysisJob: { jobId: 1 },
|
||||
metricBaseline: {
|
||||
metricId: 1,
|
||||
role: 1,
|
||||
cohort: 1,
|
||||
patch: 1,
|
||||
featureSchemaVersion: 1,
|
||||
},
|
||||
championStyleProfile: {
|
||||
championId: 1,
|
||||
role: 1,
|
||||
patch: 1,
|
||||
featureSchemaVersion: 1,
|
||||
},
|
||||
};
|
||||
|
||||
for (const [modelName, expectedKeys] of Object.entries(
|
||||
uniqueIndexesByModelName,
|
||||
)) {
|
||||
const definition = modelDefinitions.find(
|
||||
(candidate) => candidate.name === modelName,
|
||||
);
|
||||
expect(definition).toBeDefined();
|
||||
|
||||
const uniqueIndexes = definition!.schema
|
||||
.indexes()
|
||||
.filter(([, indexOptions]) => indexOptions?.unique === true)
|
||||
.map(([indexKeys]) => indexKeys);
|
||||
expect(uniqueIndexes).toContainEqual(expectedKeys);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user