~travisshears/oblastle-backend

ref: e59ff6d0 oblastle-backend/integration/imageSrcs.ts -rw-r--r-- 1.2 KiB
e59ff6d0 — Travis Shears speed up integration test 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { S3Client, ListObjectsV2Command } from '@aws-sdk/client-s3';
import { getOblasts, Oblast } from '../src/oblast';
import config from 'config';

const s3 = new S3Client({ region: config.get('AWS_REGION') });
const command = new ListObjectsV2Command({
    Bucket: 'travisshears.images',
    Prefix: 'image-service/images/oblastle/'
});
(async () => {
    console.log('testing s3 has all the needed images');
    const response = await s3.send(command);
    const keys = (response.Contents || []).map(item => item.Key);

    const oblasts = await getOblasts();
    const imageUrls: string[] = [];
    Object.keys(oblasts).forEach(async key => {
        const oblast = oblasts[key] as Record<string, any>;
        const srcKeys = Object.keys(oblast).filter(key => key.toLowerCase().includes('src'));
        srcKeys.forEach(srcKey => {
            const url = oblast[srcKey] as string;
            imageUrls.push(url);
        });
    });
    imageUrls.forEach(url => {
        const cleanURL = url.replace('http://travisshears.com/', '');
        if (!keys.includes(cleanURL)) {
            console.log(`${cleanURL} is missing from s3`);
            process.exit(1);
        }
    });
    console.log(`found all ${imageUrls.length} image srcs from oblast.yml in s3`);
})();