/** * Copyright 2022 Gravwell, Inc. All rights reserved. * * Contact: [legal@gravwell.io](mailto:legal@gravwell.io) * * This software may be modified and distributed under the terms of the MIT * license. See the LICENSE file for details. */ import { CreatableGroup } from '~/models/group/creatable-group'; import { Group } from '~/models/group/group'; import { groupDecoder } from '~/models/group/is-group'; import { UpdatableGroup } from '~/models/group/updatable-group'; import { TEST_BASE_API_CONTEXT } from '~/tests/config'; import { integrationTest, integrationTestSpecDef } from '~/tests/test-types'; import { makeCreateOneGroup } from './create-one-group'; import { makeDeleteOneGroup } from './delete-one-group'; import { makeGetAllGroups } from './get-all-groups'; import { makeGetOneGroup } from './get-one-group'; import { makeUpdateOneGroup } from './update-one-group'; describe( 'updateOneGroup()', integrationTestSpecDef(() => { let createOneGroup: ReturnType; beforeAll(async () => { createOneGroup = makeCreateOneGroup(await TEST_BASE_API_CONTEXT()); }); let getOneGroup: ReturnType; beforeAll(async () => { getOneGroup = makeGetOneGroup(await TEST_BASE_API_CONTEXT()); }); let deleteOneGroup: ReturnType; beforeAll(async () => { deleteOneGroup = makeDeleteOneGroup(await TEST_BASE_API_CONTEXT()); }); let getAllGroups: ReturnType; beforeAll(async () => { getAllGroups = makeGetAllGroups(await TEST_BASE_API_CONTEXT()); }); let updateOneGroup: ReturnType; beforeAll(async () => { updateOneGroup = makeUpdateOneGroup(await TEST_BASE_API_CONTEXT()); }); let createdGroup: Group; beforeEach(async () => { // Delete all groups const currentGroups = await getAllGroups(); const currentGroupIDs = currentGroups.map(g => g.id); const deletePromises = currentGroupIDs.map(groupID => deleteOneGroup(groupID)); await Promise.all(deletePromises); // Creates a group const data: CreatableGroup = { name: 'Name test', description: 'Description test', }; createdGroup = await createOneGroup(data); }); afterEach(async () => { // Deletes the created group await deleteOneGroup(createdGroup.id); }); it( 'Should update the group', integrationTest(async () => { const tests: Array> = [ { name: 'new name' }, { description: 'new description' }, { description: null }, { name: 'newwwww name', description: 'newwwww description' }, ]; for (const test of tests) { const data: UpdatableGroup = { ...test, id: createdGroup.id }; await updateOneGroup(data); const group = await getOneGroup(data.id); expect(groupDecoder.guard(group)).toBeTrue(); expect(group).toEqual(jasmine.objectContaining(data)); } }), ); }), );