Add device traffic reset with outbound baselines
This commit is contained in:
@@ -34,9 +34,13 @@ function createHarness({ inventory = {}, body = {} } = {}) {
|
||||
calls.push(['update', ...args]);
|
||||
return inventory.update ?? { revision: 3 };
|
||||
},
|
||||
resetTraffic: async (...args) => {
|
||||
calls.push(['resetTraffic', ...args]);
|
||||
return inventory.resetTraffic ?? { revision: 4 };
|
||||
},
|
||||
setPolicy: async (...args) => {
|
||||
calls.push(['setPolicy', ...args]);
|
||||
return inventory.setPolicy ?? { revision: 4 };
|
||||
return inventory.setPolicy ?? { revision: 5 };
|
||||
},
|
||||
};
|
||||
const route = createDeviceInventoryRoute({
|
||||
@@ -97,13 +101,23 @@ test('device route forwards metadata patch and policy arguments without coercion
|
||||
url: `/api/devices/${deviceId}/policy?source=ui`,
|
||||
}, policyResponse), true);
|
||||
assert.deepEqual(policy.calls, [['setPolicy', deviceId, 42, '8']]);
|
||||
assert.deepEqual(policyResponse.payload, { revision: 4 });
|
||||
assert.deepEqual(policyResponse.payload, { revision: 5 });
|
||||
|
||||
const reset = createHarness({ body: { expectedRevision: '9', ignored: true } });
|
||||
const resetResponse = response();
|
||||
assert.equal(await reset.route.handle({
|
||||
method: 'DELETE',
|
||||
url: '/api/devices/traffic?source=ui',
|
||||
}, resetResponse), true);
|
||||
assert.deepEqual(reset.calls, [['resetTraffic', '9']]);
|
||||
assert.deepEqual(resetResponse.payload, { revision: 4 });
|
||||
});
|
||||
|
||||
test('device route preserves endpoint gating and strict lowercase IDs', async () => {
|
||||
for (const [method, url] of [
|
||||
['POST', '/api/devices'],
|
||||
['GET', '/api/devices/refresh'],
|
||||
['GET', '/api/devices/traffic'],
|
||||
['GET', `/api/devices/${deviceId}`],
|
||||
['POST', `/api/devices/${deviceId}/policy`],
|
||||
]) {
|
||||
@@ -130,6 +144,7 @@ test('device route preserves endpoint gating and strict lowercase IDs', async ()
|
||||
for (const [method, url] of [
|
||||
['GET', '/api/devices'],
|
||||
['POST', '/api/devices/refresh'],
|
||||
['DELETE', '/api/devices/traffic'],
|
||||
['PUT', `/api/devices/${deviceId}`],
|
||||
['PUT', `/api/devices/${deviceId}/policy`],
|
||||
]) {
|
||||
@@ -149,6 +164,7 @@ test('device route propagates synchronous and asynchronous service errors unchan
|
||||
snapshot: () => { throw syncError; },
|
||||
refresh: async () => ({}),
|
||||
update: () => ({}),
|
||||
resetTraffic: async () => ({}),
|
||||
setPolicy: async () => ({}),
|
||||
},
|
||||
readBody: async () => ({}),
|
||||
@@ -164,6 +180,7 @@ test('device route propagates synchronous and asynchronous service errors unchan
|
||||
snapshot: () => ({}),
|
||||
refresh: async () => { throw asyncError; },
|
||||
update: () => ({}),
|
||||
resetTraffic: async () => ({}),
|
||||
setPolicy: async () => ({}),
|
||||
},
|
||||
readBody: async () => ({}),
|
||||
|
||||
Reference in New Issue
Block a user