fix: Add missing indices on sqlite (#6673)

* fix: enforce tag name uniqueness on sqlite

* rename migration and add other missing indices

* add tags tests
This commit is contained in:
Val
2023-07-20 10:34:45 +01:00
committed by GitHub
parent 76a765a151
commit b1838f7fab
5 changed files with 91 additions and 1 deletions

View File

@@ -24,7 +24,8 @@ export type EndpointGroup =
| 'sourceControl'
| 'eventBus'
| 'license'
| 'variables';
| 'variables'
| 'tags';
export interface SetupProps {
applyAuth?: boolean;

View File

@@ -28,6 +28,7 @@ import {
NodesController,
OwnerController,
PasswordResetController,
TagsController,
UsersController,
} from '@/controllers';
import { setupAuthMiddlewares } from '@/middlewares';
@@ -261,6 +262,14 @@ export const setupTestServer = ({
logger,
}),
);
break;
case 'tags':
registerController(
app,
config,
new TagsController({ config, externalHooks, repositories }),
);
break;
}
}
}

View File

@@ -0,0 +1,38 @@
import * as Db from '@/Db';
import * as utils from './shared/utils/';
import * as testDb from './shared/testDb';
import type { SuperAgentTest } from 'supertest';
let authOwnerAgent: SuperAgentTest;
const testServer = utils.setupTestServer({ endpointGroups: ['tags'] });
beforeAll(async () => {
const globalOwnerRole = await testDb.getGlobalOwnerRole();
const ownerShell = await testDb.createUserShell(globalOwnerRole);
authOwnerAgent = testServer.authAgentFor(ownerShell);
});
beforeEach(async () => {
await testDb.truncate(['Tag']);
});
describe('POST /tags', () => {
test('should create tag', async () => {
const resp = await authOwnerAgent.post('/tags').send({ name: 'test' });
expect(resp.statusCode).toBe(200);
const dbTag = await Db.collections.Tag.findBy({ name: 'test' });
expect(dbTag.length === 1);
});
test('should not create duplicate tag', async () => {
const newTag = Db.collections.Tag.create({ name: 'test' });
await Db.collections.Tag.save(newTag);
const resp = await authOwnerAgent.post('/tags').send({ name: 'test' });
expect(resp.status).toBe(500);
const dbTag = await Db.collections.Tag.findBy({ name: 'test' });
expect(dbTag.length).toBe(1);
});
});