|
| 1 | + |
| 2 | +// list observations in event |
| 3 | +// read observation by id |
| 4 | +// favorite an observation |
| 5 | +// unfavorite an observation |
| 6 | +// mark observation as important |
| 7 | +// unmark observation as important |
| 8 | +// transition observation state to archived |
| 9 | +// transition observation state to active |
| 10 | + |
| 11 | +import { expect } from 'chai' |
| 12 | +import { MageClientSession, SignInResult } from '../client' |
| 13 | +import { ChildProcessTestStackRef, launchTestStack } from '../stack' |
| 14 | +import * as Fixture from './fixture' |
| 15 | + |
| 16 | + |
| 17 | +describe('observations', function () { |
| 18 | + |
| 19 | + let stack: ChildProcessTestStackRef |
| 20 | + let rootSession: MageClientSession |
| 21 | + let fixture: Fixture.ObservationFixture |
| 22 | + |
| 23 | + this.timeout(15000) |
| 24 | + |
| 25 | + before('initialize stack', async function () { |
| 26 | + stack = await launchTestStack('observations') |
| 27 | + }) |
| 28 | + |
| 29 | + before('initialize fixture data', async function () { |
| 30 | + |
| 31 | + rootSession = new MageClientSession(stack.mageUrl) |
| 32 | + const rootSetup = await rootSession.setupRootUser(Fixture.rootSeed).then(x => x.data) |
| 33 | + |
| 34 | + expect(rootSetup.user.username).to.equal(Fixture.rootSeed.username) |
| 35 | + expect(rootSetup.device.uid).to.equal(Fixture.rootSeed.uid) |
| 36 | + |
| 37 | + const rootSignIn = await rootSession.signIn(Fixture.rootSeed.username, Fixture.rootSeed.password, Fixture.rootSeed.uid) as SignInResult |
| 38 | + |
| 39 | + expect(rootSignIn.user).to.exist |
| 40 | + expect(rootSignIn.user.username).to.equal(Fixture.rootSeed.username) |
| 41 | + |
| 42 | + fixture = await Fixture.populateFixtureData(rootSession) |
| 43 | + }) |
| 44 | + |
| 45 | + after('stop stack', async function () { |
| 46 | + await stack.stop() |
| 47 | + }) |
| 48 | + |
| 49 | + it('lists observations in event', async function () { |
| 50 | + const observations = await rootSession.readObservations(fixture.event.id) |
| 51 | + |
| 52 | + expect(observations).to.be.an('array').with.length.greaterThan(0) |
| 53 | + const found = observations.find(o => o.id === fixture.observation.id) |
| 54 | + expect(found, 'fixture observation not in list').to.exist |
| 55 | + }) |
| 56 | + |
| 57 | + it('reads observation by id', async function () { |
| 58 | + const obs = await rootSession.readObservation(fixture.event.id, fixture.observation.id) |
| 59 | + |
| 60 | + expect(obs.id).to.equal(fixture.observation.id) |
| 61 | + expect(obs.eventId).to.equal(fixture.event.id) |
| 62 | + expect(obs.geometry.type).to.equal('Point') |
| 63 | + }) |
| 64 | + |
| 65 | + it('favorites and unfavorites an observation', async function () { |
| 66 | + const { event, observation } = fixture |
| 67 | + |
| 68 | + const favorited = await rootSession.favoriteObservation(event.id, observation.id).then(x => x.data) |
| 69 | + expect(favorited.favoriteUserIds).to.include(rootSession.user!.id) |
| 70 | + |
| 71 | + const unfavorited = await rootSession.unfavoriteObservation(event.id, observation.id).then(x => x.data) |
| 72 | + expect(unfavorited.favoriteUserIds).not.to.include(rootSession.user!.id) |
| 73 | + }) |
| 74 | + |
| 75 | + it('marks and unmarks an observation as important', async function () { |
| 76 | + const { event, observation } = fixture |
| 77 | + const description = 'High priority incident' |
| 78 | + |
| 79 | + const marked = await rootSession.markImportant(event.id, observation.id, description).then(x => x.data) |
| 80 | + expect(marked.important).to.exist |
| 81 | + expect(marked.important!.description).to.equal(description) |
| 82 | + |
| 83 | + const unmarked = await rootSession.unmarkImportant(event.id, observation.id).then(x => x.data) |
| 84 | + expect(unmarked.important).not.to.exist |
| 85 | + }) |
| 86 | + |
| 87 | + it('adds observation state transitions', async function () { |
| 88 | + const { event, observation } = fixture |
| 89 | + |
| 90 | + const archived = await rootSession.addObservationState(event.id, observation.id, 'archive').then(x => x.data) |
| 91 | + expect(archived.name).to.equal('archive') |
| 92 | + |
| 93 | + const reactivated = await rootSession.addObservationState(event.id, observation.id, 'active').then(x => x.data) |
| 94 | + expect(reactivated.name).to.equal('active') |
| 95 | + }) |
| 96 | +}) |
0 commit comments