Skip to content

Commit f105552

Browse files
committed
test: corrected the table name of logs
1 parent a706f88 commit f105552

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

lib/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212

1313
/**
1414
* @typedef {Object} LogFilter
15-
* @property {string} [hostname]
15+
* @property {string[]} [hostnames]
1616
* @property {number} [pid]
1717
* @property {{source: string, level: string}[]} [level_json]
18+
* @property {number} [errsole_id]
1819
* @property {string[]} [sources]
1920
* @property {string[]} [levels]
2021
* @property {number} [lt_id]

tests/index.test.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ describe('ErrsolePostgres', () => {
189189
await errsolePostgres.createTables();
190190

191191
const createTableCalls = [
192-
expect.stringContaining('CREATE TABLE IF NOT EXISTS errsole_logs_v1'),
193-
expect.stringContaining('CREATE INDEX IF NOT EXISTS errsole_logs_v1_source_level_id_idx'),
194-
expect.stringContaining('CREATE INDEX IF NOT EXISTS errsole_logs_v1_source_level_timestamp_idx'),
195-
expect.stringContaining('CREATE INDEX IF NOT EXISTS errsole_logs_v1_hostname_pid_id_idx'),
192+
expect.stringContaining('CREATE TABLE IF NOT EXISTS errsole_logs_v2'),
193+
expect.stringContaining('CREATE INDEX IF NOT EXISTS errsole_logs_v2_source_level_id_idx'),
194+
expect.stringContaining('CREATE INDEX IF NOT EXISTS errsole_logs_v2_source_level_timestamp_idx'),
195+
expect.stringContaining('CREATE INDEX IF NOT EXISTS errsole_logs_v2_hostname_pid_id_idx'),
196196
expect.stringContaining('CREATE TABLE IF NOT EXISTS errsole_users'),
197197
expect.stringContaining('CREATE TABLE IF NOT EXISTS errsole_config')
198198
];
@@ -586,7 +586,7 @@ describe('ErrsolePostgres', () => {
586586
const result = await errsolePostgres.getLogs();
587587

588588
expect(poolMock.query).toHaveBeenCalledWith(
589-
expect.stringContaining('SELECT id, hostname, pid, source, timestamp, level, message FROM errsole_logs_v1'),
589+
expect.stringContaining('SELECT id, hostname, pid, source, timestamp, level, message, errsole_id FROM errsole_logs_v2'),
590590
[100]
591591
);
592592
expect(result).toEqual({ items: logs });
@@ -606,7 +606,7 @@ describe('ErrsolePostgres', () => {
606606
const result = await errsolePostgres.getLogs(filters);
607607

608608
expect(poolMock.query).toHaveBeenCalledWith(
609-
expect.stringContaining('SELECT id, hostname, pid, source, timestamp, level, message FROM errsole_logs_v1 WHERE hostname = $1 AND pid = $2 ORDER BY id DESC LIMIT $3'),
609+
expect.stringContaining('SELECT id, hostname, pid, source, timestamp, level, message, errsole_id FROM errsole_logs_v2 WHERE hostname = $1 AND pid = $2 ORDER BY id DESC LIMIT $3'),
610610
['localhost', 1234, 50]
611611
);
612612
expect(result).toEqual({ items: logs });
@@ -626,7 +626,7 @@ describe('ErrsolePostgres', () => {
626626
const result = await errsolePostgres.getLogs(filters);
627627

628628
expect(poolMock.query).toHaveBeenCalledWith(
629-
expect.stringContaining('SELECT id, hostname, pid, source, timestamp, level, message FROM errsole_logs_v1 WHERE source = ANY($1) AND level = ANY($2) ORDER BY id DESC LIMIT $3'),
629+
expect.stringContaining('SELECT id, hostname, pid, source, timestamp, level, message, errsole_id FROM errsole_logs_v2 WHERE source = ANY($1) AND level = ANY($2) ORDER BY id DESC LIMIT $3'),
630630
[['test'], ['info'], 50]
631631
);
632632
expect(result).toEqual({ items: logs });
@@ -645,7 +645,7 @@ describe('ErrsolePostgres', () => {
645645
const result = await errsolePostgres.getLogs(filters);
646646

647647
expect(poolMock.query).toHaveBeenCalledWith(
648-
expect.stringContaining('SELECT id, hostname, pid, source, timestamp, level, message FROM errsole_logs_v1 WHERE id < $1 ORDER BY id DESC LIMIT $2'),
648+
expect.stringContaining('SELECT id, hostname, pid, source, timestamp, level, message, errsole_id FROM errsole_logs_v2 WHERE id < $1 ORDER BY id DESC LIMIT $2'),
649649
[10, 50]
650650
);
651651
expect(result).toEqual({ items: logs });
@@ -664,7 +664,7 @@ describe('ErrsolePostgres', () => {
664664
const result = await errsolePostgres.getLogs(filters);
665665

666666
expect(poolMock.query).toHaveBeenCalledWith(
667-
expect.stringContaining('SELECT id, hostname, pid, source, timestamp, level, message FROM errsole_logs_v1 WHERE id > $1 ORDER BY id ASC LIMIT $2'),
667+
expect.stringContaining('SELECT id, hostname, pid, source, timestamp, level, message, errsole_id FROM errsole_logs_v2 WHERE id > $1 ORDER BY id ASC LIMIT $2'),
668668
[5, 50]
669669
);
670670
expect(result).toEqual({ items: logs });
@@ -683,7 +683,7 @@ describe('ErrsolePostgres', () => {
683683
const result = await errsolePostgres.getLogs(filters);
684684

685685
expect(poolMock.query).toHaveBeenCalledWith(
686-
expect.stringContaining('SELECT id, hostname, pid, source, timestamp, level, message FROM errsole_logs_v1 WHERE timestamp <= $1 ORDER BY id DESC LIMIT $2'),
686+
expect.stringContaining('SELECT id, hostname, pid, source, timestamp, level, message, errsole_id FROM errsole_logs_v2 WHERE timestamp <= $1 ORDER BY id DESC LIMIT $2'),
687687
[new Date('2023-01-02T00:00:00Z'), 50]
688688
);
689689
expect(result).toEqual({ items: logs });
@@ -705,7 +705,7 @@ describe('ErrsolePostgres', () => {
705705
const result = await errsolePostgres.getLogs(filters);
706706

707707
expect(poolMock.query).toHaveBeenCalledWith(
708-
expect.stringContaining('SELECT id, hostname, pid, source, timestamp, level, message FROM errsole_logs_v1'),
708+
expect.stringContaining('SELECT id, hostname, pid, source, timestamp, level, message, errsole_id FROM errsole_logs_v2'),
709709
expect.arrayContaining(['test', 'info', 'another_test', 'warn', 50])
710710
);
711711
expect(result).toEqual({ items: logs });
@@ -724,7 +724,7 @@ describe('ErrsolePostgres', () => {
724724
const result = await errsolePostgres.getLogs(filters);
725725

726726
expect(poolMock.query).toHaveBeenCalledWith(
727-
expect.stringContaining('SELECT id, hostname, pid, source, timestamp, level, message FROM errsole_logs_v1 WHERE timestamp >= $1 ORDER BY id ASC LIMIT $2'),
727+
expect.stringContaining('SELECT id, hostname, pid, source, timestamp, level, message, errsole_id FROM errsole_logs_v2 WHERE timestamp >= $1 ORDER BY id ASC LIMIT $2'),
728728
[new Date('2023-01-01T00:00:00Z'), 50]
729729
);
730730
expect(result).toEqual({ items: logs });
@@ -744,7 +744,7 @@ describe('ErrsolePostgres', () => {
744744
const result = await errsolePostgres.getLogs(filters);
745745

746746
expect(poolMock.query).toHaveBeenCalledWith(
747-
expect.stringContaining('SELECT id, hostname, pid, source, timestamp, level, message FROM errsole_logs_v1 WHERE id < $1 ORDER BY id DESC LIMIT $2'),
747+
expect.stringContaining('SELECT id, hostname, pid, source, timestamp, level, message, errsole_id FROM errsole_logs_v2 WHERE id < $1 ORDER BY id DESC LIMIT $2'),
748748
[10, 50]
749749
);
750750
expect(result.items).toEqual(logs.reverse());
@@ -756,7 +756,7 @@ describe('ErrsolePostgres', () => {
756756
await expect(errsolePostgres.getLogs()).rejects.toThrow('Query error');
757757

758758
expect(poolMock.query).toHaveBeenCalledWith(
759-
expect.stringContaining('SELECT id, hostname, pid, source, timestamp, level, message FROM errsole_logs_v1'),
759+
expect.stringContaining('SELECT id, hostname, pid, source, timestamp, level, message, errsole_id FROM errsole_logs_v2'),
760760
[100]
761761
);
762762
});
@@ -1048,7 +1048,7 @@ describe('ErrsolePostgres', () => {
10481048

10491049
const result = await errsolePostgres.getMeta(1);
10501050

1051-
expect(poolMock.query).toHaveBeenCalledWith('SELECT id, meta FROM errsole_logs_v1 WHERE id = $1', [1]);
1051+
expect(poolMock.query).toHaveBeenCalledWith('SELECT id, meta FROM errsole_logs_v2 WHERE id = $1', [1]);
10521052
expect(result).toEqual({ item: logMeta });
10531053
});
10541054

@@ -1057,7 +1057,7 @@ describe('ErrsolePostgres', () => {
10571057

10581058
await expect(errsolePostgres.getMeta(999)).rejects.toThrow('Log entry not found.');
10591059

1060-
expect(poolMock.query).toHaveBeenCalledWith('SELECT id, meta FROM errsole_logs_v1 WHERE id = $1', [999]);
1060+
expect(poolMock.query).toHaveBeenCalledWith('SELECT id, meta FROM errsole_logs_v2 WHERE id = $1', [999]);
10611061
});
10621062

10631063
it('should handle errors during query execution', async () => {
@@ -1066,7 +1066,7 @@ describe('ErrsolePostgres', () => {
10661066

10671067
await expect(errsolePostgres.getMeta(1)).rejects.toThrow('Query error');
10681068

1069-
expect(poolMock.query).toHaveBeenCalledWith('SELECT id, meta FROM errsole_logs_v1 WHERE id = $1', [1]);
1069+
expect(poolMock.query).toHaveBeenCalledWith('SELECT id, meta FROM errsole_logs_v2 WHERE id = $1', [1]);
10701070
});
10711071
});
10721072

0 commit comments

Comments
 (0)