test('add SSH key', async function (assert) { server.schema.db.sshKeys.remove(); const requestBodies = []; server.get(`/settings/ssh_key/${this.repository.id}`, function (schema, request) { return new Response(429, {}, {}); }); server.patch(`/settings/ssh_key/${this.repository.id}`, (schema, request) => { const newKey = JSON.parse(request.requestBody); requestBodies.push(newKey); newKey.id = this.repository.id; return { ssh_key: newKey }; }); await settingsPage.visit({ organization: 'org-login', repo: 'repository-name' }); await settingsPage.sshKeyForm.fillDescription('hey'); await settingsPage.sshKeyForm.fillKey('hello'); await settingsPage.sshKeyForm.add(); assert.deepEqual(requestBodies.pop().ssh_key, { id: this.repository.id, description: 'hey', value: 'hello' }); });
test('delete and set SSH keys', function (assert) { settingsPage.visit({ organization: 'killjoys', repo: 'living-a-feminist-life' }); const deletedIds = []; server.delete('/settings/ssh_key/:id', function (schema, request) { deletedIds.push(request.params.id); }); settingsPage.sshKey.delete(); andThen(() => { assert.equal(deletedIds.pop(), this.repository.id, 'expected the server to have received a deletion request for the SSH key'); assert.equal(settingsPage.sshKey.name, 'no custom key set'); assert.equal(settingsPage.sshKey.fingerprint, 'aa:bb:cc:dd'); assert.ok(settingsPage.sshKey.cannotBeDeleted, 'expected default SSH key not to be deletable'); }); const requestBodies = []; server.patch(`/settings/ssh_key/${this.repository.id}`, (schema, request) => { const newKey = JSON.parse(request.requestBody); requestBodies.push(newKey); newKey.id = this.repository.id; return { ssh_key: newKey }; }); settingsPage.sshKeyForm.fillDescription('hey'); settingsPage.sshKeyForm.fillKey('hello'); settingsPage.sshKeyForm.add(); andThen(() => { assert.deepEqual(requestBodies.pop().ssh_key, { id: this.repository.id, description: 'hey', value: 'hello' }); }); });