Skip to content

Commit

Permalink
improve tests. get rid of snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
mshustov committed May 25, 2021
1 parent ca4a965 commit 9aeee97
Showing 1 changed file with 72 additions and 117 deletions.
189 changes: 72 additions & 117 deletions src/core/server/core_usage_data/core_usage_data_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,10 @@ describe('CoreUsageDataService', () => {
elasticsearch,
});

await expect(getConfigsUsageData()).resolves.toMatchInlineSnapshot(`
Object {
"pluginA.enabled": "[redacted]",
"pluginAB.enabled": "[redacted]",
}
`);
await expect(getConfigsUsageData()).resolves.toEqual({
'pluginA.enabled': '[redacted]',
'pluginAB.enabled': '[redacted]',
});
});

it('returns an object of plugin config usage', async () => {
Expand Down Expand Up @@ -443,23 +441,21 @@ describe('CoreUsageDataService', () => {
elasticsearch,
});

await expect(getConfigsUsageData()).resolves.toMatchInlineSnapshot(`
Object {
"elasticsearch.password": "[redacted]",
"elasticsearch.username": "[redacted]",
"logging.json": false,
"pluginA.arrayOfNumbers": "[redacted]",
"pluginA.enabled": true,
"pluginA.objectConfig.debug": true,
"pluginA.objectConfig.username": "[redacted]",
"pluginAB.enabled": false,
"pluginB.arrayOfObjects": "[redacted]",
"plugins.paths": "[redacted]",
"server.basePath": "/zvt",
"server.port": 5603,
"server.rewriteBasePath": true,
}
`);
await expect(getConfigsUsageData()).resolves.toEqual({
'elasticsearch.password': '[redacted]',
'elasticsearch.username': '[redacted]',
'logging.json': false,
'pluginA.arrayOfNumbers': '[redacted]',
'pluginA.enabled': true,
'pluginA.objectConfig.debug': true,
'pluginA.objectConfig.username': '[redacted]',
'pluginAB.enabled': false,
'pluginB.arrayOfObjects': '[redacted]',
'plugins.paths': '[redacted]',
'server.basePath': '/zvt',
'server.port': 5603,
'server.rewriteBasePath': true,
});
});

describe('config explicitly exposed to usage', () => {
Expand All @@ -482,12 +478,10 @@ describe('CoreUsageDataService', () => {
elasticsearch,
});

await expect(getConfigsUsageData()).resolves.toMatchInlineSnapshot(`
Object {
"pluginA.objectConfig.debug": "[redacted]",
"server.basePath": "[redacted]",
}
`);
await expect(getConfigsUsageData()).resolves.toEqual({
'pluginA.objectConfig.debug': '[redacted]',
'server.basePath': '[redacted]',
});
});

it('returns config value on safe complete match', async () => {
Expand All @@ -503,11 +497,9 @@ describe('CoreUsageDataService', () => {
elasticsearch,
});

await expect(getConfigsUsageData()).resolves.toMatchInlineSnapshot(`
Object {
"server.basePath": "/zvt",
}
`);
await expect(getConfigsUsageData()).resolves.toEqual({
'server.basePath': '/zvt',
});
});

it('returns [redacted] on unsafe parent match', async () => {
Expand All @@ -526,12 +518,10 @@ describe('CoreUsageDataService', () => {
elasticsearch,
});

await expect(getConfigsUsageData()).resolves.toMatchInlineSnapshot(`
Object {
"pluginA.objectConfig.debug": "[redacted]",
"pluginA.objectConfig.username": "[redacted]",
}
`);
await expect(getConfigsUsageData()).resolves.toEqual({
'pluginA.objectConfig.debug': '[redacted]',
'pluginA.objectConfig.username': '[redacted]',
});
});

it('returns config value on safe parent match', async () => {
Expand All @@ -550,12 +540,10 @@ describe('CoreUsageDataService', () => {
elasticsearch,
});

await expect(getConfigsUsageData()).resolves.toMatchInlineSnapshot(`
Object {
"pluginA.objectConfig.debug": true,
"pluginA.objectConfig.username": "some_user",
}
`);
await expect(getConfigsUsageData()).resolves.toEqual({
'pluginA.objectConfig.debug': true,
'pluginA.objectConfig.username': 'some_user',
});
});

it('returns [redacted] on explicitly marked as safe array of objects', async () => {
Expand All @@ -571,11 +559,9 @@ describe('CoreUsageDataService', () => {
elasticsearch,
});

await expect(getConfigsUsageData()).resolves.toMatchInlineSnapshot(`
Object {
"pluginB.arrayOfObjects": "[redacted]",
}
`);
await expect(getConfigsUsageData()).resolves.toEqual({
'pluginB.arrayOfObjects': '[redacted]',
});
});

it('returns values on explicitly marked as safe array of numbers', async () => {
Expand All @@ -591,15 +577,9 @@ describe('CoreUsageDataService', () => {
elasticsearch,
});

await expect(getConfigsUsageData()).resolves.toMatchInlineSnapshot(`
Object {
"pluginA.arrayOfNumbers": Array [
1,
2,
3,
],
}
`);
await expect(getConfigsUsageData()).resolves.toEqual({
'pluginA.arrayOfNumbers': [1, 2, 3],
});
});

it('returns values on explicitly marked as safe array of strings', async () => {
Expand All @@ -615,15 +595,9 @@ describe('CoreUsageDataService', () => {
elasticsearch,
});

await expect(getConfigsUsageData()).resolves.toMatchInlineSnapshot(`
Object {
"plugins.paths": Array [
"pluginA",
"pluginAB",
"pluginB",
],
}
`);
await expect(getConfigsUsageData()).resolves.toEqual({
'plugins.paths': ['pluginA', 'pluginAB', 'pluginB'],
});
});
});

Expand All @@ -644,12 +618,10 @@ describe('CoreUsageDataService', () => {
elasticsearch,
});

await expect(getConfigsUsageData()).resolves.toMatchInlineSnapshot(`
Object {
"pluginA.objectConfig.debug": "[redacted]",
"pluginA.objectConfig.username": "[redacted]",
}
`);
await expect(getConfigsUsageData()).resolves.toEqual({
'pluginA.objectConfig.debug': '[redacted]',
'pluginA.objectConfig.username': '[redacted]',
});
});

it('returns config value on safe parent match', async () => {
Expand All @@ -665,13 +637,11 @@ describe('CoreUsageDataService', () => {
elasticsearch,
});

await expect(getConfigsUsageData()).resolves.toMatchInlineSnapshot(`
Object {
"elasticsearch.password": "[redacted]",
"elasticsearch.username": "[redacted]",
"pluginA.objectConfig.username": "[redacted]",
}
`);
await expect(getConfigsUsageData()).resolves.toEqual({
'elasticsearch.password': '[redacted]',
'elasticsearch.username': '[redacted]',
'pluginA.objectConfig.username': '[redacted]',
});
});

it('returns [redacted] on implicit array of objects', async () => {
Expand All @@ -683,11 +653,9 @@ describe('CoreUsageDataService', () => {
elasticsearch,
});

await expect(getConfigsUsageData()).resolves.toMatchInlineSnapshot(`
Object {
"pluginB.arrayOfObjects": "[redacted]",
}
`);
await expect(getConfigsUsageData()).resolves.toEqual({
'pluginB.arrayOfObjects': '[redacted]',
});
});

it('returns values on implicit array of numbers', async () => {
Expand All @@ -699,16 +667,11 @@ describe('CoreUsageDataService', () => {
elasticsearch,
});

await expect(getConfigsUsageData()).resolves.toMatchInlineSnapshot(`
Object {
"pluginA.arrayOfNumbers": Array [
1,
2,
3,
],
}
`);
await expect(getConfigsUsageData()).resolves.toEqual({
'pluginA.arrayOfNumbers': [1, 2, 3],
});
});

it('returns [redacted] on implicit array of strings', async () => {
configService.getUsedPaths.mockResolvedValue(['plugins.paths']);

Expand All @@ -718,11 +681,9 @@ describe('CoreUsageDataService', () => {
elasticsearch,
});

await expect(getConfigsUsageData()).resolves.toMatchInlineSnapshot(`
Object {
"plugins.paths": "[redacted]",
}
`);
await expect(getConfigsUsageData()).resolves.toEqual({
'plugins.paths': '[redacted]',
});
});

it('returns config value for numbers', async () => {
Expand All @@ -734,11 +695,9 @@ describe('CoreUsageDataService', () => {
elasticsearch,
});

await expect(getConfigsUsageData()).resolves.toMatchInlineSnapshot(`
Object {
"server.port": 5603,
}
`);
await expect(getConfigsUsageData()).resolves.toEqual({
'server.port': 5603,
});
});

it('returns config value for booleans', async () => {
Expand All @@ -753,12 +712,10 @@ describe('CoreUsageDataService', () => {
elasticsearch,
});

await expect(getConfigsUsageData()).resolves.toMatchInlineSnapshot(`
Object {
"logging.json": false,
"pluginA.objectConfig.debug": true,
}
`);
await expect(getConfigsUsageData()).resolves.toEqual({
'logging.json': false,
'pluginA.objectConfig.debug': true,
});
});

it('ignores exposed to usage configs but not used', async () => {
Expand All @@ -774,11 +731,9 @@ describe('CoreUsageDataService', () => {
elasticsearch,
});

await expect(getConfigsUsageData()).resolves.toMatchInlineSnapshot(`
Object {
"logging.json": false,
}
`);
await expect(getConfigsUsageData()).resolves.toEqual({
'logging.json': false,
});
});
});
});
Expand Down

0 comments on commit 9aeee97

Please sign in to comment.