Skip to content

Commit

Permalink
test(back-e2e): static map list system
Browse files Browse the repository at this point in the history
  • Loading branch information
tsa96 committed Jan 16, 2024
1 parent bd02a48 commit 7c795b0
Show file tree
Hide file tree
Showing 4 changed files with 316 additions and 7 deletions.
127 changes: 125 additions & 2 deletions apps/backend-e2e/src/admin.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ActivityType,
AdminActivityType,
Ban,
FlatMapList,
Gamemode,
MapCreditType,
MapStatus,
Expand Down Expand Up @@ -1707,7 +1708,8 @@ describe('Admin', () => {
Promise.all([
db.cleanup('mMap', 'adminActivity'),
fileStore.deleteDirectory('maps'),
fileStore.deleteDirectory('submissions')
fileStore.deleteDirectory('submissions'),
fileStore.deleteDirectory('maplist')
])
);

Expand Down Expand Up @@ -2268,6 +2270,54 @@ describe('Admin', () => {
).toHaveLength(0);
});

it('should generate new map list version files', async () => {
// This is just stored in memory so we can't test this without calling
// another endpoint. In future we could probably just peer inside of
// Redis.
const oldVersion = await req.get({
url: 'maps/maplistversion',
status: 200,
token: adminToken
});

await req.patch({
url: `admin/maps/${map.id}`,
status: 204,
body: { status: MapStatus.APPROVED, finalLeaderboards },
token: adminToken
});

const newVersion = await req.get({
url: 'maps/maplistversion',
status: 200,
token: adminToken
});

expect(newVersion.body.approved).toBe(oldVersion.body.approved + 1);
expect(newVersion.body.submissions).toBe(
oldVersion.body.submissions + 1
);

const approvedMapList = await fileStore.getMapListVersion(
FlatMapList.APPROVED,
newVersion.body.approved
);
expect(approvedMapList).toHaveLength(1);
expect(approvedMapList[0]).toMatchObject({
id: map.id,
leaderboards: expect.anything(),
info: expect.anything(),
thumbnail: expect.anything()
});
expect(approvedMapList[0]).not.toHaveProperty('zones');

const submissionMapList = await fileStore.getMapListVersion(
FlatMapList.SUBMISSION,
newVersion.body.submissions
);
expect(submissionMapList).toHaveLength(0);
});

it('should 400 when moving from FA to approved if leaderboards are not provided', async () => {
await req.patch({
url: `admin/maps/${map.id}`,
Expand All @@ -2278,6 +2328,48 @@ describe('Admin', () => {
});
});

it('should generate a new map list version file without the map when the map gets disabled', async () => {
const oldVersion = await req.get({
url: 'maps/maplistversion',
status: 200,
token: adminToken
});

const map1 = await db.createMap({
...createMapData,
status: MapStatusNew.APPROVED
});
const map2 = await db.createMap({
...createMapData,
name: 'surf_thisfileistoobig',
fileName: 'aaaaaaaaaa',
status: MapStatusNew.APPROVED
});

await req.patch({
url: `admin/maps/${map1.id}`,
status: 204,
body: { status: MapStatusNew.DISABLED },
token: adminToken
});

const newVersion = await req.get({
url: 'maps/maplistversion',
status: 200,
token: adminToken
});

expect(newVersion.body.submissions).toBe(oldVersion.body.submissions);
expect(newVersion.body.approved).toBe(oldVersion.body.approved + 1);

const approvedMapList = await fileStore.getMapListVersion(
FlatMapList.APPROVED,
newVersion.body.approved
);
expect(approvedMapList).toHaveLength(1);
expect(approvedMapList[0]).toMatchObject({ id: map2.id });
});

it('should return 404 if map not found', () =>
req.patch({
url: `admin/maps/${NULL_ID}`,
Expand Down Expand Up @@ -2320,7 +2412,9 @@ describe('Admin', () => {
await db.createLbRun({ map: m1, user: u1, time: 1, rank: 1 });
});

afterEach(() => db.cleanup('mMap'));
afterEach(() =>
Promise.all([db.cleanup('mMap'), fileStore.deleteDirectory('/maplist')])
);

it('should successfully delete the map and related stored data', async () => {
const fileName = 'my_cool_map';
Expand Down Expand Up @@ -2379,6 +2473,35 @@ describe('Admin', () => {
).toBe(true);
});

it('should update the map list version', async () => {
const oldVersion = await req.get({
url: 'maps/maplistversion',
status: 200,
token: adminToken
});

await req.del({
url: `admin/maps/${m1.id}`,
status: 204,
token: adminToken
});

const newVersion = await req.get({
url: 'maps/maplistversion',
status: 200,
token: adminToken
});

expect(newVersion.body.submissions).toBe(oldVersion.body.submissions);
expect(newVersion.body.approved).toBe(oldVersion.body.approved + 1);

const approvedMapList = await fileStore.getMapListVersion(
FlatMapList.APPROVED,
newVersion.body.approved
);
expect(approvedMapList).toHaveLength(0);
});

it('should return 404 if map not found', () =>
req.del({
url: `admin/maps/${NULL_ID}`,
Expand Down
29 changes: 29 additions & 0 deletions apps/backend-e2e/src/maps-2.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
setupE2ETestEnvironment,
teardownE2ETestEnvironment
} from './support/environment';
import { MapListVersionDto } from '../../backend/src/app/dto/map/map-list-version.dto';

describe('Maps Part 2', () => {
let app,
Expand All @@ -64,6 +65,34 @@ describe('Maps Part 2', () => {

afterAll(() => teardownE2ETestEnvironment(app));

describe('maps/maplist', () => {
describe('GET', () => {
let token;
beforeAll(async () => (token = await db.loginNewUser()));
afterAll(() => db.cleanup('user'));

it('should respond with map lists', async () => {
// We really don't have to test much here, since these values are just
// stored in memory. Tests doing map submission and approval test this
// system more thoroughly.
const res = await req.get({
url: 'maps/maplistversion',
status: 200,
validate: MapListVersionDto,
token
});

expect(res.body).toMatchObject({
approved: expect.any(Number),
submissions: expect.any(Number)
});
});

it('should 401 when no access token is provided', () =>
req.unauthorizedTest('maps/maplistversion', 'get'));
});
});

describe('maps/{mapID}/info', () => {
describe('GET', () => {
let token, map;
Expand Down
Loading

0 comments on commit 7c795b0

Please sign in to comment.