Skip to content

Commit 91489cf

Browse files
chore(test): unmatched nocks to recorded correctly
1 parent 96b973b commit 91489cf

File tree

18 files changed

+87
-138
lines changed

18 files changed

+87
-138
lines changed

src/sitemap/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export async function hasSimpleSitemap(context, info) {
7272
}
7373
return attributes.hasSimpleSitemap;
7474
}
75+
7576
/**
7677
* Returns a flag indicating whether a simple sitemap was just added to a project.
7778
*

test/auth/authenticate.test.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -619,13 +619,7 @@ describe('Authentication Test', () => {
619619
});
620620

621621
describe('Org API Token', () => {
622-
beforeEach(() => {
623-
nock.siteConfig().reply(404);
624-
});
625-
626622
it('supports api tokens with permissions but on no org/site route', async () => {
627-
nock.orgConfig(ORG_CONFIG);
628-
629623
const accessToken = await new SignJWT({
630624
email: 'helix@adobe.com',
631625
name: 'Helix Admin',

test/contentproxy/google-file.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ describe('Google File Tests', () => {
5151
pathInfo: { suffix },
5252
attributes: {
5353
authInfo: AuthInfo.Default().withAuthenticated(true),
54-
config,
5554
googleApiOpts: { retry: false },
5655
},
5756
env: {

test/discover/handler.test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@ import assert from 'assert';
1515
import { Request } from '@adobe/fetch';
1616
import { AuthInfo } from '../../src/auth/auth-info.js';
1717
import { main } from '../../src/index.js';
18-
import { Nock, SITE_CONFIG } from '../utils.js';
18+
import { Nock } from '../utils.js';
1919

2020
describe('Discover Handler Tests', () => {
2121
/** @type {import('../utils.js').NockEnv} */
2222
let nock;
2323

2424
beforeEach(() => {
2525
nock = new Nock().env();
26-
27-
nock.siteConfig(SITE_CONFIG);
2826
});
2927

3028
afterEach(() => {

test/discover/reindex.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ describe('Discover reindex tests', () => {
343343

344344
it('reindex one project returns 404 when site is not found', async () => {
345345
nock.siteConfig().reply(404);
346-
nock.inventory().reply(404);
347346

348347
const { request, context } = setupTest('org', 'site');
349348
const response = await main(request, context);

test/index/handler.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ describe('Index Handler Tests', () => {
4747
},
4848
env: {
4949
HLX_CONFIG_SERVICE_TOKEN: 'token',
50+
HELIX_STORAGE_MAX_ATTEMPTS: '1',
5051
},
5152
};
5253
return { request, context };
@@ -62,6 +63,10 @@ describe('Index Handler Tests', () => {
6263

6364
it('reports error if index definition is not found', async () => {
6465
nock.indexConfig(null);
66+
nock.sitemapConfig(null);
67+
nock.content()
68+
.head('/live/sitemap.json')
69+
.reply(404);
6570

6671
const { request, context } = setupTest();
6772
const response = await main(request, context);

test/index/update.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ describe('Index Update Tests', () => {
8888
.head('/live/sitemap.json')
8989
.reply(404)
9090
.head('/live/document.md')
91+
.optionally(true)
9192
.reply(200, '', { 'x-amz-meta-x-source-last-modified': 'Thu, 08 Jul 2021 11:04:16 GMT' });
9293
nock.indexConfig(INDEX_CONFIG);
9394
});

test/live/publish.test.js

Lines changed: 65 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -88,43 +88,7 @@ describe('Publish Action Tests', () => {
8888
return { request, context };
8989
}
9090

91-
describe('no indexing or sitemap configuration', () => {
92-
beforeEach(() => {
93-
nock.indexConfig(null);
94-
nock.sitemapConfig(null);
95-
nock.content()
96-
.head('/live/sitemap.json')
97-
.reply(200, [])
98-
.putObject('/live/sitemap.json')
99-
.reply(201);
100-
});
101-
102-
it('publish document', async () => {
103-
nock.content()
104-
.head('/preview/index.md')
105-
.reply(200, '', { 'last-modified': 'Thu, 08 Jul 2021 10:04:16 GMT' })
106-
.copyObject('/live/index.md')
107-
.reply(200, new xml2js.Builder().buildObject({
108-
CopyObjectResult: {
109-
LastModified: '2021-05-05T08:37:23.000Z',
110-
ETag: '"f278c0035a9b4398629613a33abe6451"',
111-
},
112-
}))
113-
.head('/live/index.md')
114-
.reply(200, '', { 'last-modified': 'Thu, 08 Jul 2021 10:04:16 GMT' });
115-
116-
const { request, context } = setupTest('/');
117-
const response = await main(request, context);
118-
119-
assert.strictEqual(response.status, 200);
120-
assert.deepStrictEqual(purgeInfos, [
121-
{ path: '/' },
122-
{ path: '/index.plain.html' },
123-
{ key: 'DiyvKbkf2MaZORJJ' },
124-
{ key: '8lnjgOWBwsoqAQXB' },
125-
]);
126-
});
127-
91+
describe('documents that do not trigger index update', () => {
12892
it('publish redirects', async () => {
12993
nock.content()
13094
.head('/preview/redirects.json')
@@ -165,15 +129,6 @@ describe('Publish Action Tests', () => {
165129
ETag: '"f278c0035a9b4398629613a33abe6451"',
166130
},
167131
}))
168-
.getObject('/live/redirects.json')
169-
.reply(200, {
170-
default: {
171-
data: {
172-
source: '/from',
173-
destination: '/to',
174-
},
175-
},
176-
})
177132
.head('/live/redirects.json')
178133
.reply(200, '', { 'last-modified': 'Thu, 08 Jul 2021 10:04:16 GMT' });
179134

@@ -187,27 +142,6 @@ describe('Publish Action Tests', () => {
187142
assert.strictEqual(response.status, 200);
188143
});
189144

190-
it('publish metadata', async () => {
191-
nock.content()
192-
.head('/preview/metadata.json')
193-
.reply(200)
194-
.copyObject('/live/metadata.json')
195-
.reply(200, new xml2js.Builder().buildObject({
196-
CopyObjectResult: {
197-
LastModified: '2021-05-05T08:37:23.000Z',
198-
ETag: '"f278c0035a9b4398629613a33abe6451"',
199-
},
200-
}))
201-
.head('/live/metadata.json')
202-
.reply(200, '', { 'last-modified': 'Thu, 08 Jul 2021 10:04:16 GMT' });
203-
204-
const { request, context } = setupTest(METADATA_JSON_PATH);
205-
const response = await main(request, context);
206-
207-
assert.strictEqual(response.status, 200);
208-
assert.deepStrictEqual(surrogates, ['U_NW4adJU7Qazf-I']);
209-
});
210-
211145
it('reports an error when `contentBusCopy` returns 404', async () => {
212146
nock.content()
213147
.head('/preview/index.md')
@@ -230,6 +164,68 @@ describe('Publish Action Tests', () => {
230164
'x-error': `source does not exist: helix-content-bus/${SITE_CONFIG.content.contentBusId}/preview/index.md`,
231165
});
232166
});
167+
});
168+
169+
describe('sitemap, but no indexing configuration', () => {
170+
const SITEMAP_CONFIG = `
171+
version: 1
172+
sitemaps:
173+
default:
174+
source: /sitemap-index.json
175+
destination: /sitemap.xml
176+
`;
177+
178+
beforeEach(() => {
179+
nock.indexConfig(null);
180+
nock.sitemapConfig(SITEMAP_CONFIG);
181+
});
182+
183+
it('publish document', async () => {
184+
nock.content()
185+
.head('/preview/index.md')
186+
.reply(200, '', { 'last-modified': 'Thu, 08 Jul 2021 10:04:16 GMT' })
187+
.copyObject('/live/index.md')
188+
.reply(200, new xml2js.Builder().buildObject({
189+
CopyObjectResult: {
190+
LastModified: '2021-05-05T08:37:23.000Z',
191+
ETag: '"f278c0035a9b4398629613a33abe6451"',
192+
},
193+
}))
194+
.head('/live/index.md')
195+
.reply(200, '', { 'last-modified': 'Thu, 08 Jul 2021 10:04:16 GMT' });
196+
197+
const { request, context } = setupTest('/');
198+
const response = await main(request, context);
199+
200+
assert.strictEqual(response.status, 200);
201+
assert.deepStrictEqual(purgeInfos, [
202+
{ path: '/' },
203+
{ path: '/index.plain.html' },
204+
{ key: 'DiyvKbkf2MaZORJJ' },
205+
{ key: '8lnjgOWBwsoqAQXB' },
206+
]);
207+
});
208+
209+
it('publish metadata', async () => {
210+
nock.content()
211+
.head('/preview/metadata.json')
212+
.reply(200)
213+
.copyObject('/live/metadata.json')
214+
.reply(200, new xml2js.Builder().buildObject({
215+
CopyObjectResult: {
216+
LastModified: '2021-05-05T08:37:23.000Z',
217+
ETag: '"f278c0035a9b4398629613a33abe6451"',
218+
},
219+
}))
220+
.head('/live/metadata.json')
221+
.reply(200, '', { 'last-modified': 'Thu, 08 Jul 2021 10:04:16 GMT' });
222+
223+
const { request, context } = setupTest(METADATA_JSON_PATH);
224+
const response = await main(request, context);
225+
226+
assert.strictEqual(response.status, 200);
227+
assert.deepStrictEqual(surrogates, ['U_NW4adJU7Qazf-I']);
228+
});
233229

234230
it('tweaks status when `contentBusCopy` returns 404 and a redirect matches', async () => {
235231
nock.content()
@@ -242,13 +238,14 @@ describe('Publish Action Tests', () => {
242238
Message: 'The specified key does not exist.',
243239
},
244240
}))
241+
.head('/live/index.md')
242+
.reply(404)
245243
.putObject('/live/index.md')
246244
.reply(201, function fn(uri, body) {
247245
assert.strictEqual(this.req.headers['x-amz-meta-redirect-location'], '/target');
248246
assert.strictEqual(body, '/target');
249247
})
250248
.head('/live/index.md')
251-
.twice()
252249
.reply(200, '', { 'last-modified': 'Thu, 08 Jul 2021 10:04:16 GMT' });
253250

254251
const { request, context } = setupTest('/', {

test/live/unpublish.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe('Publish Remove Tests', () => {
8484
return { request, context };
8585
}
8686

87-
describe('no indexing or sitemap configuration', () => {
87+
describe('regular operation', () => {
8888
beforeEach(() => {
8989
nock.indexConfig(null);
9090
nock.sitemapConfig(null);
@@ -133,7 +133,9 @@ describe('Publish Remove Tests', () => {
133133
},
134134
}]);
135135
});
136+
});
136137

138+
describe('operation fails', () => {
137139
it('fails to remove document when source exists', async () => {
138140
sandbox.stub(web2edit, 'lookup')
139141
.returns({ editUrl: 'yep, still here!' });
@@ -172,8 +174,6 @@ describe('Publish Remove Tests', () => {
172174
.returns({ status: 404 });
173175

174176
nock.content()
175-
.head('/live/redirects.json')
176-
.reply(404)
177177
.deleteObject('/live/redirects.json')
178178
.reply(204);
179179

test/nocks/onedrive.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ export class OneDriveNock {
3232
.optionally(contentBusId === 'default')
3333
.reply(200)
3434
.getObject('/.helix-auth/auth-onedrive-content.json')
35+
.optionally(true)
3536
.reply(200, S3CachePlugin.encrypt(contentBusId, JSON.stringify({
3637
Account: {}, AccessToken: {}, RefreshToken: {}, IdToken: {}, AppMetadata: {},
3738
})))
3839
.putObject('/.helix-auth/auth-onedrive-content.json')
39-
.optionally()
40+
.optionally(true)
4041
.reply(200);
4142
return this;
4243
}

0 commit comments

Comments
 (0)