Skip to content

Commit a425614

Browse files
author
Blanca Rosas
committed
fix: addressing PR comments
1 parent 73828d2 commit a425614

18 files changed

Lines changed: 165 additions & 156 deletions

data/init.sql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,24 @@ CREATE TABLE IF NOT EXISTS domains(
9999
CONSTRAINT domainsuffix UNIQUE (domain_suffix, tenant_id),
100100
PRIMARY KEY (name, domain_suffix, tenant_id)
101101
);
102-
CREATE TABLE IF NOT EXISTS proxiesconfigs(
103-
proxy_profile_name citext NOT NULL,
102+
CREATE TABLE IF NOT EXISTS proxyconfigs(
103+
proxy_config_name citext NOT NULL,
104104
access_info varchar(256),
105105
info_format integer,
106106
port integer,
107107
network_dns_suffix varchar(192),
108108
creation_date timestamp,
109109
tenant_id varchar(36) NOT NULL,
110-
PRIMARY KEY (proxy_profile_name, tenant_id)
110+
PRIMARY KEY (proxy_config_name, tenant_id)
111111
);
112-
CREATE TABLE IF NOT EXISTS profiles_proxiesconfigs(
113-
proxy_profile_name citext,
112+
CREATE TABLE IF NOT EXISTS profiles_proxyconfigs(
113+
proxy_config_name citext,
114114
profile_name citext,
115-
FOREIGN KEY (proxy_profile_name,tenant_id) REFERENCES proxiesconfigs(proxy_profile_name,tenant_id),
115+
FOREIGN KEY (proxy_config_name,tenant_id) REFERENCES proxyconfigs(proxy_config_name,tenant_id),
116116
FOREIGN KEY (profile_name,tenant_id) REFERENCES profiles(profile_name,tenant_id),
117117
priority integer,
118118
creation_date timestamp,
119119
created_by varchar(40),
120120
tenant_id varchar(36) NOT NULL,
121-
PRIMARY KEY (proxy_profile_name, profile_name, priority, tenant_id)
121+
PRIMARY KEY (proxy_config_name, profile_name, priority, tenant_id)
122122
);

src/data/postgres/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import { WirelessProfilesTable } from './tables/wirelessProfiles.js'
1414
import { IEEE8021xProfilesTable } from './tables/ieee8021xProfiles.js'
1515
import { readFileSync } from 'fs'
1616
import { Environment } from '../../utils/Environment.js'
17-
import { ProxiesProfilesTable } from './tables/proxiesProfiles.js'
18-
import { ProfilesProxiesConfigsTable } from './tables/profileProxyConfigs.js'
17+
import { ProxyConfigsTable } from './tables/proxyConfigs.js'
18+
import { ProfileProxyConfigsTable } from './tables/profileProxyConfigs.js'
1919

2020
export default class Db implements IDB {
2121
pool: InstanceType<typeof Pool>
@@ -25,8 +25,8 @@ export default class Db implements IDB {
2525
wirelessProfiles: WirelessProfilesTable
2626
profileWirelessConfigs: ProfilesWifiConfigsTable
2727
ieee8021xProfiles: IEEE8021xProfilesTable
28-
proxiesProfiles: ProxiesProfilesTable
29-
profileProxiesConfigs: ProfilesProxiesConfigsTable
28+
proxyConfigs: ProxyConfigsTable
29+
profileProxyConfigs: ProfileProxyConfigsTable
3030

3131
log: Logger = new Logger('PostgresDb')
3232

@@ -83,8 +83,8 @@ export default class Db implements IDB {
8383
this.wirelessProfiles = new WirelessProfilesTable(this)
8484
this.profileWirelessConfigs = new ProfilesWifiConfigsTable(this)
8585
this.ieee8021xProfiles = new IEEE8021xProfilesTable(this)
86-
this.proxiesProfiles = new ProxiesProfilesTable(this)
87-
this.profileProxiesConfigs = new ProfilesProxiesConfigsTable(this)
86+
this.proxyConfigs = new ProxyConfigsTable(this)
87+
this.profileProxyConfigs = new ProfileProxyConfigsTable(this)
8888
}
8989

9090
async query<T extends QueryResultRow>(text: string, params?: any): Promise<QueryResult<T>> {

src/data/postgres/tables/profileProxyConfigs.test.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,40 @@
66
import PostgresDb from '../index.js'
77
import { API_UNEXPECTED_EXCEPTION } from '../../../utils/constants.js'
88
import { type ProfileProxyConfigs } from '../../../models/RCS.Config.js'
9-
import { ProfilesProxiesConfigsTable } from './profileProxyConfigs.js'
9+
import { ProfileProxyConfigsTable } from './profileProxyConfigs.js'
1010
import { jest } from '@jest/globals'
1111
import { type SpyInstance, spyOn } from 'jest-mock'
1212

1313
describe('profileproxyconfig tests', () => {
1414
let db: PostgresDb
15-
let profilesProxiesConfigsTable: ProfilesProxiesConfigsTable
15+
let profilesProxyConfigsTable: ProfileProxyConfigsTable
1616
let querySpy: SpyInstance<any>
17-
const proxiesConfigs: ProfileProxyConfigs[] = [
17+
const proxyConfigs: ProfileProxyConfigs[] = [
1818
{ profileName: 'proxyConfig', priority: 1 } as any
1919
]
2020
const profileName = 'profileName'
2121
const tenantId = 'tenantId'
2222

2323
beforeEach(() => {
2424
db = new PostgresDb('')
25-
profilesProxiesConfigsTable = new ProfilesProxiesConfigsTable(db)
26-
querySpy = spyOn(profilesProxiesConfigsTable.db, 'query')
25+
profilesProxyConfigsTable = new ProfileProxyConfigsTable(db)
26+
querySpy = spyOn(profilesProxyConfigsTable.db, 'query')
2727
})
2828
afterEach(() => {
2929
jest.clearAllMocks()
3030
})
3131
describe('Get', () => {
3232
test('should Get', async () => {
3333
querySpy.mockResolvedValueOnce({ rows: [{}], rowCount: 1 })
34-
const result = await profilesProxiesConfigsTable.getProfileProxyConfigs(profileName)
34+
const result = await profilesProxyConfigsTable.getProfileProxyConfigs(profileName)
3535
expect(result).toStrictEqual([{}])
3636
expect(querySpy).toBeCalledTimes(1)
3737
expect(querySpy).toBeCalledWith(
3838
`
3939
SELECT
4040
priority as "priority",
41-
proxy_profile_name as "profileName"
42-
FROM profiles_proxiesconfigs
41+
proxy_config_name as "profileName"
42+
FROM profiles_proxyconfigs
4343
WHERE profile_name = $1 and tenant_id = $2
4444
ORDER BY priority`,
4545
[profileName, '']
@@ -49,26 +49,26 @@ describe('profileproxyconfig tests', () => {
4949
describe('Delete', () => {
5050
test('should Delete', async () => {
5151
querySpy.mockResolvedValueOnce({ rows: [{}], rowCount: 1 })
52-
const result = await profilesProxiesConfigsTable.deleteProfileProxyConfigs(profileName)
52+
const result = await profilesProxyConfigsTable.deleteProfileProxyConfigs(profileName)
5353
expect(result).toBe(true)
5454
expect(querySpy).toBeCalledTimes(1)
5555
expect(querySpy).toBeCalledWith(
5656
`
5757
DELETE
58-
FROM profiles_proxiesconfigs
58+
FROM profiles_proxyconfigs
5959
WHERE profile_name = $1 and tenant_id = $2`,
6060
[profileName, '']
6161
)
6262
})
6363
test('should Delete with tenandId', async () => {
6464
querySpy.mockResolvedValueOnce({ rows: [{}], rowCount: 1 })
65-
const result = await profilesProxiesConfigsTable.deleteProfileProxyConfigs(profileName, tenantId)
65+
const result = await profilesProxyConfigsTable.deleteProfileProxyConfigs(profileName, tenantId)
6666
expect(result).toBe(true)
6767
expect(querySpy).toBeCalledTimes(1)
6868
expect(querySpy).toBeCalledWith(
6969
`
7070
DELETE
71-
FROM profiles_proxiesconfigs
71+
FROM profiles_proxyconfigs
7272
WHERE profile_name = $1 and tenant_id = $2`,
7373
[profileName, tenantId]
7474
)
@@ -77,28 +77,28 @@ describe('profileproxyconfig tests', () => {
7777
describe('Insert', () => {
7878
test('should Insert', async () => {
7979
querySpy.mockResolvedValueOnce({ rows: [{}], rowCount: 1 })
80-
const result = await profilesProxiesConfigsTable.createProfileProxyConfigs(proxiesConfigs, profileName)
80+
const result = await profilesProxyConfigsTable.createProfileProxyConfigs(proxyConfigs, profileName)
8181
expect(result).toBe(true)
8282
expect(querySpy).toBeCalledTimes(1)
8383
expect(querySpy).toBeCalledWith(`
8484
INSERT INTO
85-
profiles_proxiesconfigs (proxy_profile_name, profile_name, priority, tenant_id)
85+
profiles_proxyconfigs (proxy_config_name, profile_name, priority, tenant_id)
8686
VALUES ('proxyConfig', 'profileName', '1', '')`)
8787
})
8888
test('should NOT insert when no proxyconfigs', async () => {
89-
await expect(profilesProxiesConfigsTable.createProfileProxyConfigs([], profileName)).rejects.toThrow(
89+
await expect(profilesProxyConfigsTable.createProfileProxyConfigs([], profileName)).rejects.toThrow(
9090
'Operation failed: profileName'
9191
)
9292
})
9393
test('should NOT insert when constraint violation', async () => {
9494
querySpy.mockRejectedValueOnce({ code: '23503', detail: 'error' })
95-
await expect(profilesProxiesConfigsTable.createProfileProxyConfigs(proxiesConfigs, profileName)).rejects.toThrow(
95+
await expect(profilesProxyConfigsTable.createProfileProxyConfigs(proxyConfigs, profileName)).rejects.toThrow(
9696
'error'
9797
)
9898
})
9999
test('should NOT insert when unknown error', async () => {
100100
querySpy.mockRejectedValueOnce('unknown')
101-
await expect(profilesProxiesConfigsTable.createProfileProxyConfigs(proxiesConfigs, profileName)).rejects.toThrow(
101+
await expect(profilesProxyConfigsTable.createProfileProxyConfigs(proxyConfigs, profileName)).rejects.toThrow(
102102
API_UNEXPECTED_EXCEPTION(profileName)
103103
)
104104
})

src/data/postgres/tables/profileProxyConfigs.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
* SPDX-License-Identifier: Apache-2.0
44
**********************************************************************/
55

6-
import { type IProfilesProxiesConfigsTable } from '../../../interfaces/database/IProfileProxyConfigsDb.js'
6+
import { type IProfileProxyConfigsTable } from '../../../interfaces/database/IProfileProxyConfigsDb.js'
77
import { type ProfileProxyConfigs } from '../../../models/RCS.Config.js'
88
import { API_UNEXPECTED_EXCEPTION } from '../../../utils/constants.js'
99
import { RPSError } from '../../../utils/RPSError.js'
1010
import format from 'pg-format'
1111
import type PostgresDb from '../index.js'
1212
import { PostgresErr } from '../errors.js'
1313

14-
export class ProfilesProxiesConfigsTable implements IProfilesProxiesConfigsTable {
14+
export class ProfileProxyConfigsTable implements IProfileProxyConfigsTable {
1515
db: PostgresDb
1616
constructor(db: PostgresDb) {
1717
this.db = db
@@ -27,8 +27,8 @@ export class ProfilesProxiesConfigsTable implements IProfilesProxiesConfigsTable
2727
`
2828
SELECT
2929
priority as "priority",
30-
proxy_profile_name as "profileName"
31-
FROM profiles_proxiesconfigs
30+
proxy_config_name as "profileName"
31+
FROM profiles_proxyconfigs
3232
WHERE profile_name = $1 and tenant_id = $2
3333
ORDER BY priority`,
3434
[profileName, tenantId]
@@ -62,7 +62,7 @@ export class ProfilesProxiesConfigsTable implements IProfilesProxiesConfigsTable
6262
format(
6363
`
6464
INSERT INTO
65-
profiles_proxiesconfigs (proxy_profile_name, profile_name, priority, tenant_id)
65+
profiles_proxyconfigs (proxy_config_name, profile_name, priority, tenant_id)
6666
VALUES %L`,
6767
configs
6868
)
@@ -91,7 +91,7 @@ export class ProfilesProxiesConfigsTable implements IProfilesProxiesConfigsTable
9191
const deleteProfileWifiResults = await this.db.query(
9292
`
9393
DELETE
94-
FROM profiles_proxiesconfigs
94+
FROM profiles_proxyconfigs
9595
WHERE profile_name = $1 and tenant_id = $2`,
9696
[profileName, tenantId]
9797
)

src/data/postgres/tables/profiles.test.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,13 @@ describe('profiles tests', () => {
8282
})
8383
test('should get count of 0 on empty rows array', async () => {
8484
const expected = 0
85-
querySpy.mockResolvedValueOnce({ rows: [], command: '', fields: null, rowCount: expected, oid: 0 })
85+
querySpy.mockResolvedValueOnce({
86+
rows: [],
87+
command: '',
88+
fields: null,
89+
rowCount: expected,
90+
oid: 0
91+
})
8692
const count: number = await profilesTable.getCount()
8793
expect(count).toBe(expected)
8894
})
@@ -125,10 +131,10 @@ describe('profiles tests', () => {
125131
COALESCE(json_agg(json_build_object('profileName',wc.wireless_profile_name, 'priority', wc.priority)) FILTER (WHERE wc.wireless_profile_name IS NOT NULL), '[]') AS "wifiConfigs",
126132
ip_sync_enabled as "ipSyncEnabled",
127133
local_wifi_sync_enabled as "localWifiSyncEnabled",
128-
COALESCE(json_agg(json_build_object('profileName',pc.proxy_profile_name, 'priority', pc.priority)) FILTER (WHERE pc.proxy_profile_name IS NOT NULL), '[]') AS "proxyConfigs"
134+
COALESCE(json_agg(json_build_object('profileName',pc.proxy_config_name, 'priority', pc.priority)) FILTER (WHERE pc.proxy_config_name IS NOT NULL), '[]') AS "proxyConfigs"
129135
FROM profiles p
130136
LEFT JOIN profiles_wirelessconfigs wc ON wc.profile_name = p.profile_name AND wc.tenant_id = p.tenant_id
131-
LEFT JOIN profiles_proxiesconfigs pc ON pc.profile_name = p.profile_name AND pc.tenant_id = p.tenant_id
137+
LEFT JOIN profiles_proxyconfigs pc ON pc.profile_name = p.profile_name AND pc.tenant_id = p.tenant_id
132138
WHERE p.tenant_id = $3
133139
GROUP BY
134140
p.profile_name,
@@ -185,10 +191,10 @@ describe('profiles tests', () => {
185191
COALESCE(json_agg(json_build_object('profileName',wc.wireless_profile_name, 'priority', wc.priority)) FILTER (WHERE wc.wireless_profile_name IS NOT NULL), '[]') AS "wifiConfigs",
186192
ip_sync_enabled as "ipSyncEnabled",
187193
local_wifi_sync_enabled as "localWifiSyncEnabled",
188-
COALESCE(json_agg(json_build_object('profileName',pc.proxy_profile_name, 'priority', pc.priority)) FILTER (WHERE pc.proxy_profile_name IS NOT NULL), '[]') AS "proxyConfigs"
194+
COALESCE(json_agg(json_build_object('profileName',pc.proxy_config_name, 'priority', pc.priority)) FILTER (WHERE pc.proxy_config_name IS NOT NULL), '[]') AS "proxyConfigs"
189195
FROM profiles p
190196
LEFT JOIN profiles_wirelessconfigs wc ON wc.profile_name = p.profile_name AND wc.tenant_id = p.tenant_id
191-
LEFT JOIN profiles_proxiesconfigs pc ON pc.profile_name = p.profile_name AND pc.tenant_id = p.tenant_id
197+
LEFT JOIN profiles_proxyconfigs pc ON pc.profile_name = p.profile_name AND pc.tenant_id = p.tenant_id
192198
WHERE p.profile_name = $1 and p.tenant_id = $2
193199
GROUP BY
194200
p.profile_name,
@@ -237,7 +243,7 @@ describe('profiles tests', () => {
237243
querySpy.mockResolvedValueOnce({ rows: [], rowCount: 1 })
238244
const wirelessConfigSpy = spyOn(db.profileWirelessConfigs, 'deleteProfileWifiConfigs')
239245
wirelessConfigSpy.mockResolvedValue(true)
240-
const profileProxyConfigsSpy = spyOn(db.profileProxiesConfigs, 'deleteProfileProxyConfigs')
246+
const profileProxyConfigsSpy = spyOn(db.profileProxyConfigs, 'deleteProfileProxyConfigs')
241247
profileProxyConfigsSpy.mockResolvedValue(true)
242248
const result = await profilesTable.delete(profileName, tenantId)
243249
expect(result).toBeTruthy()
@@ -256,7 +262,7 @@ describe('profiles tests', () => {
256262
querySpy.mockResolvedValueOnce({ rows: [], rowCount: 0 })
257263
const wirelessConfigSpy = spyOn(db.profileWirelessConfigs, 'deleteProfileWifiConfigs')
258264
wirelessConfigSpy.mockResolvedValue(false)
259-
const profileProxyConfigsSpy = spyOn(db.profileProxiesConfigs, 'deleteProfileProxyConfigs')
265+
const profileProxyConfigsSpy = spyOn(db.profileProxyConfigs, 'deleteProfileProxyConfigs')
260266
profileProxyConfigsSpy.mockResolvedValue(true)
261267
const result = await profilesTable.delete(profileName)
262268
expect(result).toBe(false)
@@ -265,7 +271,7 @@ describe('profiles tests', () => {
265271
querySpy.mockResolvedValueOnce({ rows: [], rowCount: 0 })
266272
const wirelessConfigSpy = spyOn(db.profileWirelessConfigs, 'deleteProfileWifiConfigs')
267273
wirelessConfigSpy.mockResolvedValue(true)
268-
const profileProxyConfigsSpy = spyOn(db.profileProxiesConfigs, 'deleteProfileProxyConfigs')
274+
const profileProxyConfigsSpy = spyOn(db.profileProxyConfigs, 'deleteProfileProxyConfigs')
269275
profileProxyConfigsSpy.mockResolvedValue(false)
270276
const result = await profilesTable.delete(profileName)
271277
expect(result).toBe(false)
@@ -491,7 +497,10 @@ describe('profiles tests', () => {
491497
})
492498

493499
test('should NOT update when constraint violation', async () => {
494-
querySpy.mockRejectedValueOnce({ code: '23503', message: 'profiles_cira_config_name_fkey' })
500+
querySpy.mockRejectedValueOnce({
501+
code: '23503',
502+
message: 'profiles_cira_config_name_fkey'
503+
})
495504
await expect(profilesTable.update(amtConfig)).rejects.toThrow(
496505
PROFILE_INSERTION_CIRA_CONSTRAINT(amtConfig.ciraConfigName)
497506
)
@@ -509,7 +518,7 @@ describe('profiles tests', () => {
509518
test('should insert with proxy configs', async () => {
510519
querySpy.mockResolvedValueOnce({ rows: [], rowCount: 1 })
511520

512-
const profileProxyConfigsSpy = spyOn(db.profileProxiesConfigs, 'createProfileProxyConfigs')
521+
const profileProxyConfigsSpy = spyOn(db.profileProxyConfigs, 'createProfileProxyConfigs')
513522
profileProxyConfigsSpy.mockResolvedValue(true)
514523

515524
const getByNameSpy = spyOn(profilesTable, 'getByName')
@@ -563,7 +572,7 @@ describe('profiles tests', () => {
563572
})
564573
test('should insert without proxy configs', async () => {
565574
querySpy.mockResolvedValueOnce({ rows: [], rowCount: 1 })
566-
const profileProxyConfigsSpy = spyOn(db.profileProxiesConfigs, 'createProfileProxyConfigs')
575+
const profileProxyConfigsSpy = spyOn(db.profileProxyConfigs, 'createProfileProxyConfigs')
567576
profileProxyConfigsSpy.mockResolvedValue(true)
568577
const getByNameSpy = spyOn(profilesTable, 'getByName')
569578
getByNameSpy.mockResolvedValue(amtConfig)
@@ -613,7 +622,7 @@ describe('profiles tests', () => {
613622
})
614623
test('should update with proxy configs', async () => {
615624
querySpy.mockResolvedValueOnce({ rows: [], rowCount: 1 })
616-
const profileProxyConfigsSpy = spyOn(db.profileProxiesConfigs, 'createProfileProxyConfigs')
625+
const profileProxyConfigsSpy = spyOn(db.profileProxyConfigs, 'createProfileProxyConfigs')
617626
profileProxyConfigsSpy.mockResolvedValue(true)
618627
const getByNameSpy = spyOn(profilesTable, 'getByName')
619628
amtConfig.proxyConfigs = [{} as any]

0 commit comments

Comments
 (0)