971 rest api bug sentry on filter parameters (#12088)
- fix missing createBy injection in api createOne and createMany endpoints - add a command to fix null default value for createdBySource in production entities - tested on `1747159401197/` dump extract of production db without issue
This commit is contained in:
@ -6,6 +6,9 @@ import { makeRestAPIRequest } from 'test/integration/rest/utils/make-rest-api-re
|
||||
import { deleteAllRecords } from 'test/integration/utils/delete-all-records';
|
||||
import { TEST_COMPANY_1_ID } from 'test/integration/constants/test-company-ids.constants';
|
||||
import { TEST_PRIMARY_LINK_URL } from 'test/integration/constants/test-primary-link-url.constant';
|
||||
import { TIM_ACCOUNT_ID } from 'test/integration/graphql/integration.constants';
|
||||
|
||||
import { FieldActorSource } from 'src/engine/metadata-modules/field-metadata/composite-types/actor.composite-type';
|
||||
|
||||
describe('Core REST API Create Many endpoint', () => {
|
||||
beforeEach(async () => {
|
||||
@ -43,7 +46,79 @@ describe('Core REST API Create Many endpoint', () => {
|
||||
|
||||
expect(createdPeople.length).toBe(2);
|
||||
expect(createdPeople[0].id).toBe(TEST_PERSON_1_ID);
|
||||
expect(createdPeople[0].createdBy.source).toBe(FieldActorSource.API);
|
||||
expect(createdPeople[0].createdBy.workspaceMemberId).toBe(null);
|
||||
|
||||
expect(createdPeople[1].id).toBe(TEST_PERSON_2_ID);
|
||||
expect(createdPeople[1].createdBy.source).toBe(FieldActorSource.API);
|
||||
expect(createdPeople[1].createdBy.workspaceMemberId).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a new person with specific createdBy', async () => {
|
||||
const requestBody = [
|
||||
{
|
||||
id: TEST_PERSON_1_ID,
|
||||
createdBy: {
|
||||
source: FieldActorSource.EMAIL,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: TEST_PERSON_2_ID,
|
||||
createdBy: {
|
||||
source: FieldActorSource.MANUAL,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
await makeRestAPIRequest({
|
||||
method: 'post',
|
||||
path: `/batch/people`,
|
||||
body: requestBody,
|
||||
})
|
||||
.expect(201)
|
||||
.expect((res) => {
|
||||
const createdPeople = res.body.data.createPeople;
|
||||
|
||||
expect(createdPeople[0].createdBy.source).toBe(FieldActorSource.EMAIL);
|
||||
expect(createdPeople[0].createdBy.workspaceMemberId).toBe(null);
|
||||
|
||||
expect(createdPeople[1].createdBy.source).toBe(FieldActorSource.MANUAL);
|
||||
expect(createdPeople[1].createdBy.workspaceMemberId).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
it('should create many person with MANUAL createdBy if user identified', async () => {
|
||||
const requestBody = [
|
||||
{
|
||||
id: TEST_PERSON_1_ID,
|
||||
},
|
||||
{
|
||||
id: TEST_PERSON_2_ID,
|
||||
},
|
||||
];
|
||||
|
||||
await makeRestAPIRequest({
|
||||
method: 'post',
|
||||
path: `/batch/people`,
|
||||
body: requestBody,
|
||||
bearer: ADMIN_ACCESS_TOKEN,
|
||||
})
|
||||
.expect(201)
|
||||
.expect((res) => {
|
||||
const createdPeople = res.body.data.createPeople;
|
||||
|
||||
expect(createdPeople.length).toBe(2);
|
||||
|
||||
expect(createdPeople[0].createdBy.source).toBe(FieldActorSource.MANUAL);
|
||||
expect(createdPeople[0].createdBy.workspaceMemberId).toBe(
|
||||
TIM_ACCOUNT_ID,
|
||||
);
|
||||
|
||||
expect(createdPeople[1].createdBy.source).toBe(FieldActorSource.MANUAL);
|
||||
expect(createdPeople[1].createdBy.workspaceMemberId).toBe(
|
||||
TIM_ACCOUNT_ID,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -4,6 +4,9 @@ import { TEST_PRIMARY_LINK_URL } from 'test/integration/constants/test-primary-l
|
||||
import { makeRestAPIRequest } from 'test/integration/rest/utils/make-rest-api-request.util';
|
||||
import { deleteAllRecords } from 'test/integration/utils/delete-all-records';
|
||||
import { generateRecordName } from 'test/integration/utils/generate-record-name';
|
||||
import { TIM_ACCOUNT_ID } from 'test/integration/graphql/integration.constants';
|
||||
|
||||
import { FieldActorSource } from 'src/engine/metadata-modules/field-metadata/composite-types/actor.composite-type';
|
||||
|
||||
describe('Core REST API Create One endpoint', () => {
|
||||
beforeEach(async () => {
|
||||
@ -39,6 +42,56 @@ describe('Core REST API Create One endpoint', () => {
|
||||
|
||||
expect(createdPerson.id).toBe(TEST_PERSON_1_ID);
|
||||
expect(createdPerson.city).toBe(personCity);
|
||||
expect(createdPerson.createdBy.source).toBe(FieldActorSource.API);
|
||||
expect(createdPerson.createdBy.workspaceMemberId).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a new person with specific createdBy', async () => {
|
||||
const personCity = generateRecordName(TEST_PERSON_1_ID);
|
||||
const requestBody = {
|
||||
id: TEST_PERSON_1_ID,
|
||||
city: personCity,
|
||||
companyId: TEST_COMPANY_1_ID,
|
||||
createdBy: {
|
||||
source: FieldActorSource.EMAIL,
|
||||
},
|
||||
};
|
||||
|
||||
await makeRestAPIRequest({
|
||||
method: 'post',
|
||||
path: `/people`,
|
||||
body: requestBody,
|
||||
})
|
||||
.expect(201)
|
||||
.expect((res) => {
|
||||
const createdPerson = res.body.data.createPerson;
|
||||
|
||||
expect(createdPerson.createdBy.source).toBe(FieldActorSource.EMAIL);
|
||||
expect(createdPerson.createdBy.workspaceMemberId).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a new person with MANUAL createdBy if user identified', async () => {
|
||||
const personCity = generateRecordName(TEST_PERSON_1_ID);
|
||||
const requestBody = {
|
||||
id: TEST_PERSON_1_ID,
|
||||
city: personCity,
|
||||
companyId: TEST_COMPANY_1_ID,
|
||||
};
|
||||
|
||||
await makeRestAPIRequest({
|
||||
method: 'post',
|
||||
path: `/people`,
|
||||
body: requestBody,
|
||||
bearer: ADMIN_ACCESS_TOKEN,
|
||||
})
|
||||
.expect(201)
|
||||
.expect((res) => {
|
||||
const createdPerson = res.body.data.createPerson;
|
||||
|
||||
expect(createdPerson.createdBy.source).toBe(FieldActorSource.MANUAL);
|
||||
expect(createdPerson.createdBy.workspaceMemberId).toBe(TIM_ACCOUNT_ID);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ interface RestAPIRequestParams {
|
||||
export const makeRestAPIRequest = ({
|
||||
method,
|
||||
path,
|
||||
bearer = ADMIN_ACCESS_TOKEN,
|
||||
bearer = API_KEY_ACCESS_TOKEN,
|
||||
body = {},
|
||||
}: RestAPIRequestParams) => {
|
||||
const client = request(`http://localhost:${APP_PORT}`);
|
||||
|
||||
Reference in New Issue
Block a user