Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions x-pack/plugins/case/server/saved_object_types/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,17 @@ export const userActionsMigrations = {

interface UnsanitizedComment {
comment: string;
type?: CommentType;
}

interface SanitizedComment {
comment: string;
type: CommentType;
}

interface SanitizedCommentFoSubCases {
interface SanitizedCommentForSubCases {
associationType: AssociationType;
rule: { id: string | null; name: string | null };
rule?: { id: string | null; name: string | null };
}

export const commentsMigrations = {
Expand All @@ -193,14 +194,21 @@ export const commentsMigrations = {
},
'7.12.0': (
doc: SavedObjectUnsanitizedDoc<UnsanitizedComment>
): SavedObjectSanitizedDoc<SanitizedCommentFoSubCases> => {
): SavedObjectSanitizedDoc<SanitizedCommentForSubCases> => {
let attributes: SanitizedCommentForSubCases & UnsanitizedComment = {
...doc.attributes,
associationType: AssociationType.case,
};

// only add the rule object for alert comments. Prior to 7.12 we only had CommentType.alert, generated alerts are
// introduced in 7.12.
if (doc.attributes.type === CommentType.alert) {
attributes = { ...attributes, rule: { id: null, name: null } };
}

return {
...doc,
attributes: {
...doc.attributes,
rule: { id: null, name: null },
associationType: AssociationType.case,
},
attributes,
references: doc.references || [],
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export default function createGetTests({ getService }: FtrProviderContext) {

describe('migrations', () => {
before(async () => {
await esArchiver.load('cases/migrations');
await esArchiver.load('cases/migrations/7.10.0');
});

after(async () => {
await esArchiver.unload('cases/migrations');
await esArchiver.unload('cases/migrations/7.10.0');
});

it('7.11.0 migrates cases comments', async () => {
Expand Down
91 changes: 62 additions & 29 deletions x-pack/test/case_api_integration/basic/tests/cases/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,74 @@ export default function createGetTests({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');

describe('migrations', () => {
before(async () => {
await esArchiver.load('cases/migrations');
});
// tests upgrading a 7.10.0 saved object to the latest version
describe('7.10.0 -> latest stack version', () => {
before(async () => {
await esArchiver.load('cases/migrations/7.10.0');
});

after(async () => {
await esArchiver.unload('cases/migrations');
});
after(async () => {
await esArchiver.unload('cases/migrations/7.10.0');
});

it('migrates cases connector', async () => {
const { body } = await supertest
.get(`${CASES_URL}/e1900ac0-017f-11eb-93f8-d161651bf509`)
.set('kbn-xsrf', 'true')
.send()
.expect(200);

expect(body).key('connector');
expect(body).not.key('connector_id');
expect(body.connector).to.eql({
id: 'connector-1',
name: 'none',
type: '.none',
fields: null,
});
});

it('7.10.0 migrates cases connector', async () => {
const { body } = await supertest
.get(`${CASES_URL}/e1900ac0-017f-11eb-93f8-d161651bf509`)
.set('kbn-xsrf', 'true')
.send()
.expect(200);

expect(body).key('connector');
expect(body).not.key('connector_id');
expect(body.connector).to.eql({
id: 'connector-1',
name: 'none',
type: '.none',
fields: null,
it('migrates cases settings', async () => {
const { body } = await supertest
.get(`${CASES_URL}/e1900ac0-017f-11eb-93f8-d161651bf509`)
.set('kbn-xsrf', 'true')
.send()
.expect(200);

expect(body).key('settings');
expect(body.settings).to.eql({
syncAlerts: true,
});
});
});

it('7.11.0 migrates cases settings', async () => {
const { body } = await supertest
.get(`${CASES_URL}/e1900ac0-017f-11eb-93f8-d161651bf509`)
.set('kbn-xsrf', 'true')
.send()
.expect(200);
// tests upgrading a 7.11.1 saved object to the latest version
describe('7.11.1 -> latest stack version', () => {
const caseID = '2ea28c10-7855-11eb-9ca6-83ec5acb735f';
before(async () => {
await esArchiver.load('cases/migrations/7.11.1');
});

after(async () => {
await esArchiver.unload('cases/migrations/7.11.1');
});

it('adds rule info to only alert comments for 7.12', async () => {
// user comment
let { body } = await supertest
.get(`${CASES_URL}/${caseID}/comments/34a20a00-7855-11eb-9ca6-83ec5acb735f`)
.expect(200);

expect(body).not.key('rule');
expect(body.rule).to.eql(undefined);

// alert comment
({ body } = await supertest
.get(`${CASES_URL}/${caseID}/comments/3178f2b0-7857-11eb-9ca6-83ec5acb735f`)
.expect(200));

expect(body).key('settings');
expect(body.settings).to.eql({
syncAlerts: true,
expect(body).key('rule');
expect(body.rule).to.eql({ id: null, name: null });
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export default function createGetTests({ getService }: FtrProviderContext) {

describe('migrations', () => {
before(async () => {
await esArchiver.load('cases/migrations');
await esArchiver.load('cases/migrations/7.10.0');
});

after(async () => {
await esArchiver.unload('cases/migrations');
await esArchiver.unload('cases/migrations/7.10.0');
});

it('7.10.0 migrates user actions connector', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export default function createGetTests({ getService }: FtrProviderContext) {

describe('migrations', () => {
before(async () => {
await esArchiver.load('cases/migrations');
await esArchiver.load('cases/migrations/7.10.0');
});

after(async () => {
await esArchiver.unload('cases/migrations');
await esArchiver.unload('cases/migrations/7.10.0');
});

it('7.10.0 migrates configure cases connector', async () => {
Expand Down
Binary file not shown.
Binary file not shown.
Loading